Added ImageDrawable to listview

pull/41/head
Michael Schättgen 9 years ago
parent 59402d30ff
commit f11145ce95

@ -5,7 +5,7 @@
<GradleProjectSettings>
<option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.10" />
<option name="gradleHome" value="F:\Android\Android Studio\gradle\gradle-2.14.1" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />

@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

@ -3,8 +3,6 @@
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Aegis.iml" filepath="$PROJECT_DIR$/Aegis.iml" />
<module fileurl="file://$PROJECT_DIR$/Aegis.iml" filepath="$PROJECT_DIR$/Aegis.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
</modules>
</component>

@ -19,10 +19,12 @@ android {
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:design:24.1.1'
compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
compile 'me.dm7.barcodescanner:zxing:1.9'
compile 'com.android.support:cardview-v7:24.1.1'
compile 'com.android.support:recyclerview-v7:24.1.1'

@ -1,5 +1,6 @@
package me.impy.aegis;
import android.graphics.Color;
import android.os.Handler;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
@ -10,9 +11,13 @@ import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.amulyakhare.textdrawable.TextDrawable;
import com.amulyakhare.textdrawable.util.ColorGenerator;
import java.security.Key;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
@ -37,18 +42,21 @@ public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.Ke
public static class KeyProfileHolder extends RecyclerView.ViewHolder {
TextView profileName;
TextView profileCode;
ImageView profileDrawable;
KeyProfile keyProfile;
KeyProfileHolder(View itemView) {
super(itemView);
profileName = (TextView) itemView.findViewById(R.id.profile_name);
profileCode = (TextView) itemView.findViewById(R.id.profile_code);
profileDrawable = (ImageView) itemView.findViewById(R.id.ivTextDrawable);
}
public void setData(KeyProfile profile) {
this.keyProfile = profile;
profileName.setText(profile.Name);
profileCode.setText(profile.Code);
profileDrawable.setImageDrawable(generateTextDrawable(profile));
}
public void updateCode() {
@ -63,6 +71,19 @@ public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.Ke
}
profileCode.setText(otp.substring(0, 3) + " " + otp.substring(3));
}
private TextDrawable generateTextDrawable(KeyProfile profile)
{
if(profileName == null)
return null;
ColorGenerator generator = ColorGenerator.MATERIAL; // or use DEFAULT
// generate color based on a key (same key returns the same color), useful for list/grid views
int profileKeyColor = generator.getColor(profile.Name);
TextDrawable newDrawable = TextDrawable.builder().buildRound(profile.Name.substring(0, 1), profileKeyColor);
return newDrawable;
}
}
// Provide a suitable constructor (depends on the kind of dataset)

@ -26,7 +26,7 @@ public class ScannerActivity extends Activity implements ZXingScannerView.Result
@Override
public void onCreate(Bundle state) {
super.onCreate(state);
//handleDummyResult();
handleDummyResult();
mScannerView = new ZXingScannerView(this) {
@Override

@ -4,45 +4,63 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingLeft="16dp">
<ImageView android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/ivTextDrawable"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="wrap_content"
android:padding="16dp"
android:layout_alignParentBottom="false"
android:layout_alignParentTop="false"
android:layout_alignWithParentIfMissing="false"
android:gravity="bottom"
android:id="@+id/relativeLayout"
android:layout_alignParentStart="false">
<RelativeLayout
android:layout_width="match_parent"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:layout_alignParentBottom="false"
android:layout_alignParentTop="false"
android:layout_alignWithParentIfMissing="false"
android:gravity="bottom"
android:id="@+id/relativeLayout"
android:layout_alignParentStart="false">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/profile_code"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:textSize="36sp"
android:textColor="?android:attr/textColorPrimary"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/profile_name"
android:text="Post title"
android:layout_below="@+id/profile_code"
android:textSize="20sp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
</RelativeLayout>
</LinearLayout>
android:id="@+id/profile_name"
android:text="Post title"
android:textSize="20sp"
android:layout_below="@+id/profile_code"
android:layout_alignLeft="@+id/profile_code"
android:layout_alignStart="@+id/profile_code"
android:ellipsize="end"
android:maxLines="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/profile_code"
android:textSize="36sp"
android:textColor="?android:attr/textColorPrimary"
android:layout_marginLeft="6dp"
android:layout_marginStart="6dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>

@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.android.tools.build:gradle:2.2.0-beta1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

@ -1,6 +1,6 @@
#Mon Dec 28 10:00:20 PST 2015
#Sun Aug 21 21:51:34 CEST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

Loading…
Cancel
Save