Search in sources :

Example 91 with UP

use of android.support.v7.widget.helper.ItemTouchHelper.UP in project Android-Password-Store by zeapo.

the class AutofillFragment method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    // this fragment is only created from the settings page (AutofillPreferenceActivity)
    // need to interact with the recyclerAdapter which is a member of activity
    final AutofillPreferenceActivity callingActivity = (AutofillPreferenceActivity) getActivity();
    LayoutInflater inflater = callingActivity.getLayoutInflater();
    @SuppressLint("InflateParams") final View view = inflater.inflate(R.layout.fragment_autofill, null);
    builder.setView(view);
    final String packageName = getArguments().getString("packageName");
    final String appName = getArguments().getString("appName");
    isWeb = getArguments().getBoolean("isWeb");
    // set the dialog icon and title or webURL editText
    String iconPackageName;
    if (!isWeb) {
        iconPackageName = packageName;
        builder.setTitle(appName);
        view.findViewById(R.id.webURL).setVisibility(View.GONE);
    } else {
        iconPackageName = "com.android.browser";
        builder.setTitle("Website");
        ((EditText) view.findViewById(R.id.webURL)).setText(packageName);
    }
    try {
        builder.setIcon(callingActivity.getPackageManager().getApplicationIcon(iconPackageName));
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    // set up the listview now for items added by button/from preferences
    adapter = new ArrayAdapter<String>(getActivity().getApplicationContext(), android.R.layout.simple_list_item_1, android.R.id.text1) {

        // set text color to black because default is white...
        @NonNull
        @Override
        public View getView(int position, View convertView, @NonNull ViewGroup parent) {
            TextView textView = (TextView) super.getView(position, convertView, parent);
            textView.setTextColor(ContextCompat.getColor(getContext(), R.color.grey_black_1000));
            return textView;
        }
    };
    ((ListView) view.findViewById(R.id.matched)).setAdapter(adapter);
    // delete items by clicking them
    ((ListView) view.findViewById(R.id.matched)).setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            adapter.remove(adapter.getItem(position));
        }
    });
    // set the existing preference, if any
    SharedPreferences prefs;
    if (!isWeb) {
        prefs = getActivity().getApplicationContext().getSharedPreferences("autofill", Context.MODE_PRIVATE);
    } else {
        prefs = getActivity().getApplicationContext().getSharedPreferences("autofill_web", Context.MODE_PRIVATE);
    }
    String preference = prefs.getString(packageName, "");
    switch(preference) {
        case "":
            ((RadioButton) view.findViewById(R.id.use_default)).toggle();
            break;
        case "/first":
            ((RadioButton) view.findViewById(R.id.first)).toggle();
            break;
        case "/never":
            ((RadioButton) view.findViewById(R.id.never)).toggle();
            break;
        default:
            ((RadioButton) view.findViewById(R.id.match)).toggle();
            // trim to remove the last blank element
            adapter.addAll(preference.trim().split("\n"));
    }
    // add items with the + button
    View.OnClickListener matchPassword = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ((RadioButton) view.findViewById(R.id.match)).toggle();
            Intent intent = new Intent(getActivity(), PasswordStore.class);
            intent.putExtra("matchWith", true);
            startActivityForResult(intent, MATCH_WITH);
        }
    };
    view.findViewById(R.id.matchButton).setOnClickListener(matchPassword);
    // write to preferences when OK clicked
    builder.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
        }
    });
    builder.setNegativeButton(R.string.dialog_cancel, null);
    final SharedPreferences.Editor editor = prefs.edit();
    if (isWeb) {
        builder.setNeutralButton(R.string.autofill_apps_delete, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (callingActivity.recyclerAdapter != null && packageName != null && !packageName.equals("")) {
                    editor.remove(packageName);
                    callingActivity.recyclerAdapter.removeWebsite(packageName);
                    editor.apply();
                }
            }
        });
    }
    return builder.create();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) ListView(android.widget.ListView) PackageManager(android.content.pm.PackageManager) NonNull(android.support.annotation.NonNull) TextView(android.widget.TextView) EditText(android.widget.EditText) SharedPreferences(android.content.SharedPreferences) ViewGroup(android.view.ViewGroup) Intent(android.content.Intent) RadioButton(android.widget.RadioButton) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) SuppressLint(android.annotation.SuppressLint) LayoutInflater(android.view.LayoutInflater) SuppressLint(android.annotation.SuppressLint) AdapterView(android.widget.AdapterView)

Example 92 with UP

use of android.support.v7.widget.helper.ItemTouchHelper.UP in project Android-Password-Store by zeapo.

the class PasswordStore method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    Intent intent;
    Log.d("PASS", "Menu item " + id + " pressed");
    AlertDialog.Builder initBefore = new AlertDialog.Builder(this).setMessage(this.getResources().getString(R.string.creation_dialog_text)).setPositiveButton(this.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
        }
    });
    switch(id) {
        case R.id.user_pref:
            try {
                intent = new Intent(this, UserPreference.class);
                startActivity(intent);
            } catch (Exception e) {
                System.out.println("Exception caught :(");
                e.printStackTrace();
            }
            return true;
        case R.id.git_push:
            if (!PasswordRepository.isInitialized()) {
                initBefore.show();
                break;
            }
            intent = new Intent(this, GitActivity.class);
            intent.putExtra("Operation", GitActivity.REQUEST_PUSH);
            startActivityForResult(intent, GitActivity.REQUEST_PUSH);
            return true;
        case R.id.git_pull:
            if (!PasswordRepository.isInitialized()) {
                initBefore.show();
                break;
            }
            intent = new Intent(this, GitActivity.class);
            intent.putExtra("Operation", GitActivity.REQUEST_PULL);
            startActivityForResult(intent, GitActivity.REQUEST_PULL);
            return true;
        case R.id.git_sync:
            if (!PasswordRepository.isInitialized()) {
                initBefore.show();
                break;
            }
            intent = new Intent(this, GitActivity.class);
            intent.putExtra("Operation", GitActivity.REQUEST_SYNC);
            startActivityForResult(intent, GitActivity.REQUEST_SYNC);
            return true;
        case R.id.refresh:
            updateListAdapter();
            return true;
        case android.R.id.home:
            Log.d("PASS", "Home pressed");
            this.onBackPressed();
            break;
        default:
            break;
    }
    return super.onOptionsItemSelected(item);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) GitActivity(com.zeapo.pwdstore.git.GitActivity) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) SuppressLint(android.annotation.SuppressLint) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException)

Example 93 with UP

use of android.support.v7.widget.helper.ItemTouchHelper.UP in project teamward-client by Neamar.

the class GameActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the AccountsActivity/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    // noinspection SimplifiableIfStatement
    if (id == android.R.id.home) {
        mDrawerLayout.openDrawer(GravityCompat.START);
    } else if (id == R.id.action_about) {
        new AlertDialog.Builder(this).setTitle(R.string.action_about).setMessage(getString(R.string.about_text)).setPositiveButton(R.string.rammus_ok, new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        }).show();
        return true;
    } else if (id == R.id.action_counter) {
        Intent counterIntent = new Intent(GameActivity.this, CounterChampionsActivity.class);
        counterIntent.putExtra("account", account);
        startActivity(counterIntent);
        return true;
    }
    return super.onOptionsItemSelected(item);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent)

Example 94 with UP

use of android.support.v7.widget.helper.ItemTouchHelper.UP in project teamward-client by Neamar.

the class GameActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (!BuildConfig.DEBUG) {
        // Do not use NewRelic on DEBUG.
        NewRelic.withApplicationToken("AAcab2a6606aca33f2716f49d2c60e68234953a103").start(this.getApplication());
    }
    setContentView(R.layout.activity_game);
    // First run: open accounts activity, finish this activity
    AccountManager accountManager = new AccountManager(this);
    if (accountManager.getAccounts().isEmpty()) {
        Intent i = new Intent(this, AccountsActivity.class);
        startActivity(i);
        Tracker.trackFirstTimeAppOpen(GameActivity.this);
        finish();
        return;
    }
    // Get account
    if (getIntent() != null && getIntent().hasExtra("account")) {
        account = (Account) getIntent().getSerializableExtra("account");
    } else {
        account = accountManager.getAccounts().get(0);
        if (getIntent() != null && getIntent().getAction() != null && getIntent().getAction().equals(Intent.ACTION_MAIN)) {
            getIntent().putExtra("source", "app_open");
        }
    }
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    assert toolbar != null;
    setSupportActionBar(toolbar);
    ActionBar ab = getSupportActionBar();
    assert ab != null;
    ab.setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp);
    ab.setDisplayHomeAsUpEnabled(true);
    ab.setTitle(R.string.title_activity_game);
    mViewPager = (ViewPager) findViewById(R.id.container);
    mTabLayout = (TabLayout) findViewById(R.id.tabs);
    Button refreshButton = (Button) findViewById(R.id.refresh);
    mEmptyView = findViewById(android.R.id.empty);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager(), this);
    // Set up the ViewPager with the sections adapter.
    assert mViewPager != null;
    assert mTabLayout != null;
    mViewPager.setAdapter(sectionsPagerAdapter);
    mTabLayout.setupWithViewPager(mViewPager);
    assert refreshButton != null;
    refreshButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            setUiMode(UI_MODE_LOADING);
            loadCurrentGame(account.summonerName, account.region);
        }
    });
    TextView notInGame = ((TextView) findViewById(R.id.summoner_not_in_game_text));
    assert notInGame != null;
    notInGame.setText(String.format(getString(R.string.s_is_not_in_game_right_now), account.summonerName));
    setUiMode(UI_MODE_LOADING);
    if (savedInstanceState == null || !savedInstanceState.containsKey("game")) {
        loadCurrentGame(account.summonerName, account.region);
    }
    if (TokenRefreshedService.tokenUpdateRequired(this)) {
        Log.i(TAG, "Syncing FCM token with server");
        // Resync token with server
        Intent intent = new Intent(this, SyncTokenService.class);
        this.startService(intent);
    }
}
Also used : Button(android.widget.Button) Intent(android.content.Intent) TextView(android.widget.TextView) SectionsPagerAdapter(fr.neamar.lolgamedata.adapter.SectionsPagerAdapter) View(android.view.View) TextView(android.widget.TextView) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Example 95 with UP

use of android.support.v7.widget.helper.ItemTouchHelper.UP in project android_packages_apps_Settings by omnirom.

the class PowerUsageAnomalyDetailsTest method testRefreshUi_displayCorrectTitleAndSummary.

@Test
public void testRefreshUi_displayCorrectTitleAndSummary() {
    final List<Preference> testPreferences = new ArrayList<>();
    final ArgumentCaptor<Preference> preferenceCaptor = ArgumentCaptor.forClass(Preference.class);
    Answer<Void> prefCallable = new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            testPreferences.add(preferenceCaptor.getValue());
            return null;
        }
    };
    doAnswer(prefCallable).when(mAbnormalListGroup).addPreference(preferenceCaptor.capture());
    mFragment.refreshUi();
    final Preference wakelockPreference = testPreferences.get(0);
    assertThat(wakelockPreference.getTitle()).isEqualTo(NAME_APP_1);
    assertThat(wakelockPreference.getSummary()).isEqualTo("Keeping device awake");
    final Preference wakeupPreference = testPreferences.get(1);
    assertThat(wakeupPreference.getTitle()).isEqualTo(NAME_APP_2);
    assertThat(wakeupPreference.getSummary()).isEqualTo("Waking up device in background");
    final Preference bluetoothPreference = testPreferences.get(2);
    assertThat(bluetoothPreference.getTitle()).isEqualTo(NAME_APP_3);
    assertThat(bluetoothPreference.getSummary()).isEqualTo("Requesting location frequently");
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Preference(android.support.v7.preference.Preference) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

View (android.view.View)135 RecyclerView (android.support.v7.widget.RecyclerView)97 TextView (android.widget.TextView)69 Toolbar (android.support.v7.widget.Toolbar)51 ActionBar (android.support.v7.app.ActionBar)49 Intent (android.content.Intent)44 ImageView (android.widget.ImageView)41 AdapterView (android.widget.AdapterView)33 ArrayList (java.util.ArrayList)30 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)29 DialogInterface (android.content.DialogInterface)25 AlertDialog (android.support.v7.app.AlertDialog)25 ListView (android.widget.ListView)25 Bundle (android.os.Bundle)22 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)22 SharedPreferences (android.content.SharedPreferences)21 Preference (android.support.v7.preference.Preference)20 GridLayoutManager (android.support.v7.widget.GridLayoutManager)19 SuppressLint (android.annotation.SuppressLint)16 Point (android.graphics.Point)16