Different backgrounds on drawer header long press

This commit is contained in:
Yaroslav Berezanskyi 2015-08-13 17:03:28 +03:00
parent 3fbb32f262
commit ed23bf723f
17 changed files with 109 additions and 9 deletions

View File

@ -47,6 +47,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import io.syng.R; import io.syng.R;
import io.syng.adapter.BackgroundArrayAdapter;
import io.syng.adapter.DAppDrawerAdapter; import io.syng.adapter.DAppDrawerAdapter;
import io.syng.adapter.DAppDrawerAdapter.OnDAppClickListener; import io.syng.adapter.DAppDrawerAdapter.OnDAppClickListener;
import io.syng.adapter.ProfileDrawerAdapter; import io.syng.adapter.ProfileDrawerAdapter;
@ -61,7 +62,7 @@ import static android.view.View.VISIBLE;
import static org.ethereum.config.SystemProperties.CONFIG; import static org.ethereum.config.SystemProperties.CONFIG;
public abstract class BaseActivity extends AppCompatActivity implements public abstract class BaseActivity extends AppCompatActivity implements
OnClickListener, OnDAppClickListener, OnProfileClickListener { OnClickListener, OnDAppClickListener, OnProfileClickListener, View.OnLongClickListener {
private static final Logger logger = LoggerFactory.getLogger("SyngApplication"); private static final Logger logger = LoggerFactory.getLogger("SyngApplication");
@ -94,6 +95,7 @@ public abstract class BaseActivity extends AppCompatActivity implements
}; };
private List<Profile> mProfiles; private List<Profile> mProfiles;
private List<Dapp> mDApps; private List<Dapp> mDApps;
private ImageView mHeaderImageView;
protected abstract void onDAppClick(Dapp dapp); protected abstract void onDAppClick(Dapp dapp);
@ -134,8 +136,8 @@ public abstract class BaseActivity extends AppCompatActivity implements
findViewById(R.id.ll_import_wallet).setOnClickListener(this); findViewById(R.id.ll_import_wallet).setOnClickListener(this);
findViewById(R.id.ll_settings).setOnClickListener(this); findViewById(R.id.ll_settings).setOnClickListener(this);
findViewById(R.id.ll_contribute).setOnClickListener(this); findViewById(R.id.ll_contribute).setOnClickListener(this);
findViewById(R.id.drawer_header).setOnClickListener(this); findViewById(R.id.drawer_header_item).setOnClickListener(this);
findViewById(R.id.drawer_header_item).setOnLongClickListener(this);
mFrontView = findViewById(R.id.ll_front_view); mFrontView = findViewById(R.id.ll_front_view);
mBackView = findViewById(R.id.ll_back_view); mBackView = findViewById(R.id.ll_back_view);
@ -150,8 +152,8 @@ public abstract class BaseActivity extends AppCompatActivity implements
mDAppsRecyclerView.setLayoutManager(layoutManager1); mDAppsRecyclerView.setLayoutManager(layoutManager1);
initDApps(); initDApps();
ImageView header = (ImageView) findViewById(R.id.iv_header); mHeaderImageView = (ImageView) findViewById(R.id.iv_header);
Glide.with(this).load(R.drawable.drawer).into(header); Glide.with(this).load(R.drawable.bg0).into(mHeaderImageView);
GeneralUtil.showWarningDialogIfNeed(this); GeneralUtil.showWarningDialogIfNeed(this);
} }
@ -339,7 +341,7 @@ public abstract class BaseActivity extends AppCompatActivity implements
startActivity(new Intent(BaseActivity.this, SettingsActivity.class)); startActivity(new Intent(BaseActivity.this, SettingsActivity.class));
closeDrawer(DRAWER_CLOSE_DELAY_LONG); closeDrawer(DRAWER_CLOSE_DELAY_LONG);
break; break;
case R.id.drawer_header: case R.id.drawer_header_item:
flipDrawer(); flipDrawer();
break; break;
} }
@ -598,4 +600,22 @@ public abstract class BaseActivity extends AppCompatActivity implements
showAccountCreateDialog(); showAccountCreateDialog();
} }
@Override
public boolean onLongClick(View v) {
if (v.getId() == R.id.drawer_header_item) {
new MaterialDialog.Builder(this)
.adapter(new BackgroundArrayAdapter(this),
new MaterialDialog.ListCallback() {
@SuppressWarnings("ConstantConditions")
@Override
public void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
BackgroundArrayAdapter adapter = (BackgroundArrayAdapter) dialog.getListView().getAdapter();
Glide.with(BaseActivity.this).load(adapter.getImageResourceIdByPosition(which)).into(mHeaderImageView);
dialog.dismiss();
}
})
.show();
}
return true;
}
} }

View File

@ -0,0 +1,60 @@
package io.syng.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import io.syng.R;
public class BackgroundArrayAdapter extends ArrayAdapter<Integer> {
private static final List<Integer> sItems = new ArrayList<>(
Arrays.asList(R.drawable.bg0_resized, R.drawable.bg1_resized, R.drawable.bg2_resized, R.drawable.bg3_resized));
public BackgroundArrayAdapter(Context context) {
super(context, 0, sItems);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.backround_list_item, parent, false);
viewHolder = new ViewHolder(convertView);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
Glide.with(getContext()).load(getItem(position)).into(viewHolder.backgroundImage);
return convertView;
}
static class ViewHolder {
View backgroundView;
ImageView backgroundImage;
public ViewHolder(View view) {
backgroundView = view.findViewById(R.id.ll_background);
backgroundImage = (ImageView) view.findViewById(R.id.iv_background);
}
}
public int getImageResourceIdByPosition(int position) {
return sItems.get(position);
}
}

View File

@ -80,7 +80,7 @@ public class ConsoleFragment extends Fragment implements ConnectorHandler {
mConsoleText.setMovementMethod(new ScrollingMovementMethod()); mConsoleText.setMovementMethod(new ScrollingMovementMethod());
ImageView background = (ImageView) view.findViewById(R.id.iv_background); ImageView background = (ImageView) view.findViewById(R.id.iv_background);
Glide.with(this).load(R.drawable.bg1).into(background); Glide.with(this).load(R.drawable.console_bg).into(background);
ImageView syngLogo = (ImageView) view.findViewById(R.id.iv_syng_logo); ImageView syngLogo = (ImageView) view.findViewById(R.id.iv_syng_logo);
ImageView syngText = (ImageView) view.findViewById(R.id.iv_syng_text); ImageView syngText = (ImageView) view.findViewById(R.id.iv_syng_text);

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 197 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 254 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

View File

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/ll_background"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="150dp"
android:maxWidth="320dp"
android:background="?selectableItemBackground"
android:orientation="vertical">
<ImageView
android:id="@+id/iv_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
tools:src="@drawable/two"
/>
</LinearLayout>

View File

@ -1,5 +1,5 @@
<FrameLayout <FrameLayout
android:id="@+id/drawer_header" android:id="@+id/drawer_header_item"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="120dp" android:layout_height="120dp"

View File

@ -4,7 +4,7 @@
<item name="android:layout_width">fill_parent</item> <item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">match_parent</item> <item name="android:layout_height">match_parent</item>
<item name="android:layout_gravity">start</item> <item name="android:layout_gravity">start</item>
<item name="android:background">@drawable/bg1</item> <item name="android:background">@drawable/console_bg</item>
<item name="android:orientation">vertical</item> <item name="android:orientation">vertical</item>
</style> </style>