Added ImageDrawable to listview

This commit is contained in:
Michael Schättgen 2016-08-21 21:55:04 +02:00
parent 59402d30ff
commit f11145ce95
9 changed files with 82 additions and 43 deletions

2
.idea/gradle.xml generated
View file

@ -5,7 +5,7 @@
<GradleProjectSettings> <GradleProjectSettings>
<option name="distributionType" value="LOCAL" /> <option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="$PROJECT_DIR$" /> <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"> <option name="modules">
<set> <set>
<option value="$PROJECT_DIR$" /> <option value="$PROJECT_DIR$" />

2
.idea/misc.xml generated
View file

@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" /> <ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" /> <ConfirmationsSetting value="0" id="Remove" />
</component> </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" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

2
.idea/modules.xml generated
View file

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

View file

@ -19,10 +19,12 @@ android {
} }
} }
dependencies { dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.1.1' compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:design: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 'me.dm7.barcodescanner:zxing:1.9'
compile 'com.android.support:cardview-v7:24.1.1' compile 'com.android.support:cardview-v7:24.1.1'
compile 'com.android.support:recyclerview-v7:24.1.1' compile 'com.android.support:recyclerview-v7:24.1.1'

View file

@ -1,5 +1,6 @@
package me.impy.aegis; package me.impy.aegis;
import android.graphics.Color;
import android.os.Handler; import android.os.Handler;
import android.support.v7.widget.CardView; import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
@ -10,9 +11,13 @@ import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.amulyakhare.textdrawable.TextDrawable;
import com.amulyakhare.textdrawable.util.ColorGenerator;
import java.security.Key; import java.security.Key;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
@ -37,18 +42,21 @@ public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.Ke
public static class KeyProfileHolder extends RecyclerView.ViewHolder { public static class KeyProfileHolder extends RecyclerView.ViewHolder {
TextView profileName; TextView profileName;
TextView profileCode; TextView profileCode;
ImageView profileDrawable;
KeyProfile keyProfile; KeyProfile keyProfile;
KeyProfileHolder(View itemView) { KeyProfileHolder(View itemView) {
super(itemView); super(itemView);
profileName = (TextView) itemView.findViewById(R.id.profile_name); profileName = (TextView) itemView.findViewById(R.id.profile_name);
profileCode = (TextView) itemView.findViewById(R.id.profile_code); profileCode = (TextView) itemView.findViewById(R.id.profile_code);
profileDrawable = (ImageView) itemView.findViewById(R.id.ivTextDrawable);
} }
public void setData(KeyProfile profile) { public void setData(KeyProfile profile) {
this.keyProfile = profile; this.keyProfile = profile;
profileName.setText(profile.Name); profileName.setText(profile.Name);
profileCode.setText(profile.Code); profileCode.setText(profile.Code);
profileDrawable.setImageDrawable(generateTextDrawable(profile));
} }
public void updateCode() { public void updateCode() {
@ -63,6 +71,19 @@ public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.Ke
} }
profileCode.setText(otp.substring(0, 3) + " " + otp.substring(3)); 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) // Provide a suitable constructor (depends on the kind of dataset)

View file

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

View file

@ -5,10 +5,23 @@
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<LinearLayout <LinearLayout
android:orientation="vertical" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="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 <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -24,21 +37,26 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" android:id="@+id/profile_name"
android:text="Medium Text" android:text="Post title"
android:id="@+id/profile_code" android:textSize="20sp"
android:layout_alignParentStart="true" android:layout_below="@+id/profile_code"
android:layout_alignParentLeft="true" android:layout_alignLeft="@+id/profile_code"
android:textSize="36sp" android:layout_alignStart="@+id/profile_code"
android:textColor="?android:attr/textColorPrimary"/> android:ellipsize="end"
android:maxLines="1"/>
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/profile_name" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Post title" android:text="Medium Text"
android:layout_below="@+id/profile_code" android:id="@+id/profile_code"
android:textSize="20sp" 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_alignParentLeft="true"
android:layout_alignParentStart="true"/> android:layout_alignParentStart="true"/>

View file

@ -5,7 +5,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { 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 // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files

View file

@ -1,6 +1,6 @@
#Mon Dec 28 10:00:20 PST 2015 #Sun Aug 21 21:51:34 CEST 2016
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists 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