From f6f4d26645594b62c8cc05310f409f5f38d5eeb4 Mon Sep 17 00:00:00 2001 From: arrase Date: Tue, 29 Nov 2016 01:41:41 +0100 Subject: [PATCH] type selection spinner --- .../HiddenServicesActivity.java | 40 ++++++++++++++++++- app/src/main/res/menu/hs_menu.xml | 10 ++++- app/src/main/res/values/arrays.xml | 5 ++- app/src/main/res/values/strings.xml | 1 + 4 files changed, 53 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/torproject/android/ui/hiddenservices/HiddenServicesActivity.java b/app/src/main/java/org/torproject/android/ui/hiddenservices/HiddenServicesActivity.java index 5771701d..99af1828 100644 --- a/app/src/main/java/org/torproject/android/ui/hiddenservices/HiddenServicesActivity.java +++ b/app/src/main/java/org/torproject/android/ui/hiddenservices/HiddenServicesActivity.java @@ -8,13 +8,16 @@ import android.database.Cursor; import android.os.Bundle; import android.os.Handler; import android.support.design.widget.FloatingActionButton; +import android.support.v4.view.MenuItemCompat; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; +import android.widget.ArrayAdapter; import android.widget.ListView; +import android.widget.Spinner; import android.widget.Toast; import org.torproject.android.R; @@ -29,6 +32,7 @@ public class HiddenServicesActivity extends AppCompatActivity { public final int WRITE_EXTERNAL_STORAGE_FROM_ACTIONBAR = 1; private ContentResolver mResolver; private OnionListAdapter mAdapter; + private FloatingActionButton fab; private String mWhere = HSContentProvider.HiddenService.CREATED_BY_USER + "=1"; @@ -43,7 +47,7 @@ public class HiddenServicesActivity extends AppCompatActivity { mResolver = getContentResolver(); - FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); + fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -96,6 +100,40 @@ public class HiddenServicesActivity extends AppCompatActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.hs_menu, menu); + + MenuItem item = menu.findItem(R.id.hs_type); + Spinner spinner = (Spinner) MenuItemCompat.getActionView(item); + + ArrayAdapter adapter = ArrayAdapter.createFromResource( + this, R.array.array_hs_types, android.R.layout.simple_spinner_item); + + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + + spinner.setAdapter(adapter); + + spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + + @Override + public void onItemSelected(AdapterView arg0, View v, int pos, long id) { + if (pos == 0) { + mWhere = HSContentProvider.HiddenService.CREATED_BY_USER + "=1"; + fab.show(); + } else { + mWhere = HSContentProvider.HiddenService.CREATED_BY_USER + "=0"; + fab.hide(); + } + + mAdapter.changeCursor(mResolver.query( + HSContentProvider.CONTENT_URI, HSContentProvider.PROJECTION, mWhere, null, null + )); + } + + @Override + public void onNothingSelected(AdapterView arg0) { + // Do nothing + } + }); + return true; } diff --git a/app/src/main/res/menu/hs_menu.xml b/app/src/main/res/menu/hs_menu.xml index cfe580d6..e82a935d 100644 --- a/app/src/main/res/menu/hs_menu.xml +++ b/app/src/main/res/menu/hs_menu.xml @@ -1,5 +1,13 @@ - + + + diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 795a4198..d0f22015 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -9,5 +9,8 @@ Get New Bridges - + + User services + App services + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f189cd33..c8af6bb9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -361,4 +361,5 @@ Start Tor again for finish the process Confirm service deletion Click again for backup + Service type