Example usage for android.view View.OnClickListener View.OnClickListener

List of usage examples for android.view View.OnClickListener View.OnClickListener

Introduction

In this page you can find the example usage for android.view View.OnClickListener View.OnClickListener.

Prototype

View.OnClickListener

Source Link

Usage

From source file:no.digipost.android.gui.content.ThreadPerTaskExecutor.java

/**
 * Called when the activity is first created.
 *///from  w w w .  j av a2s .c o  m
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pdf);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    toolbar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showInformationDialog();
        }
    });
    ((DigipostApplication) getApplication()).getTracker(DigipostApplication.TrackerName.APP_TRACKER);
    selectActionModeCallback = new SelectActionModeCallback();
    mAlertBuilder = new AlertDialog.Builder(this);
    intent = getIntent();
    String openFilepath = intent.getStringExtra(ACTION_OPEN_FILEPATH);
    if (openFilepath != null) {
        setActionBar(FilenameUtils.getName(openFilepath));
        core = openFile(openFilepath);
        SearchTaskResult.set(null);
    } else if (core == null && DocumentContentStore.getDocumentContent() != null) {
        setActionBar(DocumentContentStore.getDocumentAttachment().getSubject());

        byte buffer[] = DocumentContentStore.getDocumentContent();

        if (buffer != null) {
            core = openBuffer(buffer);
        }

        SearchTaskResult.set(null);
    }

    if (core == null) {
        AlertDialog alert = mAlertBuilder.create();
        alert.setTitle(R.string.pdf_open_failed);
        alert.setButton(AlertDialog.BUTTON_POSITIVE, this.getString(R.string.close),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                });
        alert.show();
        return;
    }

    createUI();

    if (savedInstanceState != null) {
        mDocView.setDisplayedViewIndex(savedInstanceState.getInt(CURRENT_WINDOW, 0));
    }

    if (super.shouldShowInvoiceOptionsDialog(this)) {
        super.showInvoiceOptionsDialog(this);
    }
    super.showMetadata();
}

From source file:com.zapto.park.ParkActivity.java

public boolean onOptionsItemSelected(MenuItem item) {
    Intent i = null;//from w  ww  . jav a2s. c o m
    switch (item.getItemId()) {
    // Add User
    case 1:
        Dialog d = new Dialog(cActivity);
        final Dialog dialog = d;
        d.setContentView(R.layout.dialog_add_employee);
        d.setTitle(R.string.create_user_title);

        final EditText first_name = (EditText) d.findViewById(R.id.employee_first);
        final EditText last_name = (EditText) d.findViewById(R.id.employee_last);
        Button button_getinfo = (Button) d.findViewById(R.id.button_getinfo);

        button_getinfo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EmployeeDB edb = new EmployeeDB(context);

                String first = first_name.getText().toString();
                String last = last_name.getText().toString();

                ContentValues cv = new ContentValues();
                cv.put("totable_first", first);
                cv.put("totable_last", last);
                cv.put("totable_license", Globals.LICENSE_KEY);

                // Log request in database.
                ContentValues cv2 = new ContentValues();
                cv2.put("first", first);
                cv2.put("last", last);

                // Query database.
                edb.insertEmployee(cv2);

                // Close our database.
                edb.close();

                dialog.dismiss();
            }
        });

        d.show();

        break;
    // Settings
    case 2:
        Log.i(LOG_TAG, "Settings menu clicked.");
        i = new Intent(this, SettingsActivity.class);
        startActivity(i);
        break;
    case 3:
        Log.i(LOG_TAG, "View Log Loading.");
        i = new Intent(this, ListViewActivity.class);
        startActivity(i);
        break;
    case 4:
        doInit();
        Handler handler = new Handler();
        handler.post(new Runnable() {
            @Override
            public void run() {
                updateEmployees();
                doPendingRequests();
            }
        });
        break;
    case 5:
        Log.i(LOG_TAG, "SendEmailActivity Loading.");
        i = new Intent(this, SendEmailActivity.class);
        startActivity(i);
        break;
    case 6:
        Log.i(LOG_TAG, "View Log Loading.");
        i = new Intent(this, ListViewActivity.class);
        startActivity(i);
        break;
    }

    return true;
}

From source file:com.vuze.android.remote.fragment.FilesFragment.java

public View onCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container,
        Bundle savedInstanceState) {//from ww w .j a  v a 2 s  .  c  om

    if (AndroidUtils.DEBUG) {
        Log.d(TAG, "onCreateview " + this);
    }

    View view = inflater.inflate(R.layout.frag_torrent_files, container, false);

    FragmentActivity activity = getActivity();

    progressBar = (ProgressBar) activity.findViewById(R.id.details_progress_bar);

    viewAreaToggleEditMode = view.findViewById(R.id.files_area_toggleditmode);
    tvScrollTitle = (TextView) view.findViewById(R.id.files_scrolltitle);

    btnEditMode = (CompoundButton) view.findViewById(R.id.files_editmode);
    if (btnEditMode != null) {
        btnEditMode.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (adapter == null) {
                    return;
                }
                adapter.setInEditMode(btnEditMode.isChecked());
            }
        });
    }

    final SwipeRefreshLayoutExtra swipeRefresh = (SwipeRefreshLayoutExtra) view
            .findViewById(R.id.swipe_container);
    if (swipeRefresh != null) {
        swipeRefresh.setExtraLayout(R.layout.swipe_layout_extra);
        swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                if (sessionInfo == null) {
                    return;
                }
                showProgressBar();
                sessionInfo.executeRpc(new RpcExecuter() {
                    @Override
                    public void executeRpc(TransmissionRPC rpc) {
                        rpc.getTorrentFileInfo(TAG, torrentID, null, new TorrentListReceivedListener() {

                            @Override
                            public void rpcTorrentListReceived(String callID, List<?> addedTorrentMaps,
                                    List<?> removedTorrentIDs) {
                                AndroidUtils.runOnUIThread(FilesFragment.this, new Runnable() {
                                    @Override
                                    public void run() {
                                        swipeRefresh.setRefreshing(false);
                                    }
                                });
                            }
                        });
                    }
                });

            }
        });
        swipeRefresh.setOnExtraViewVisibilityChange(this);
    }

    listview = (RecyclerView) view.findViewById(R.id.files_list);
    listview.setLayoutManager(new PreCachingLayoutManager(getContext()));
    listview.setAdapter(adapter);

    listview.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            {
                if (event.getAction() != KeyEvent.ACTION_DOWN) {
                    return false;
                }
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_RIGHT: {
                    // expand
                    int i = adapter.getSelectedPosition();
                    FilesAdapterDisplayObject item = adapter.getItem(i);
                    if (item instanceof FilesAdapterDisplayFolder) {
                        if (!((FilesAdapterDisplayFolder) item).expand) {
                            ((FilesAdapterDisplayFolder) item).expand = true;
                            adapter.getFilter().filter("");
                            return true;
                        }
                    }
                    break;
                }

                case KeyEvent.KEYCODE_DPAD_LEFT: {
                    // collapse
                    int i = adapter.getSelectedPosition();
                    FilesAdapterDisplayObject item = adapter.getItem(i);
                    if (item instanceof FilesAdapterDisplayFolder) {
                        if (((FilesAdapterDisplayFolder) item).expand) {
                            ((FilesAdapterDisplayFolder) item).expand = false;
                            adapter.getFilter().filter("");
                            return true;
                        }
                    }
                    break;
                }

                case KeyEvent.KEYCODE_MEDIA_PLAY:
                case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: {
                    launchOrStreamFile();
                    return true;
                }
                }

                return false;
            }
        }
    });

    listview.setOnScrollListener(new RecyclerView.OnScrollListener() {
        int firstVisibleItem = 0;

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            LinearLayoutManager lm = (LinearLayoutManager) listview.getLayoutManager();
            int firstVisibleItem = lm.findFirstCompletelyVisibleItemPosition();
            if (firstVisibleItem != this.firstVisibleItem) {
                this.firstVisibleItem = firstVisibleItem;
                FilesAdapterDisplayObject itemAtPosition = adapter.getItem(firstVisibleItem);
                //               Log.d(TAG, "itemAt" + firstVisibleItem + " is " + itemAtPosition);
                //               Log.d(TAG, "tvScrollTitle=" + tvScrollTitle);
                //               Log.d(TAG, "viewAreaToggleEditMode=" + viewAreaToggleEditMode);

                if (itemAtPosition == null) {
                    return;
                }
                if (itemAtPosition.parent != null) {
                    if (viewAreaToggleEditMode != null) {
                        viewAreaToggleEditMode.setVisibility(View.GONE);
                    }
                    if (tvScrollTitle != null) {
                        tvScrollTitle.setVisibility(View.VISIBLE);
                        tvScrollTitle.setText(itemAtPosition.parent.folder);
                    }
                } else {
                    if (viewAreaToggleEditMode != null) {
                        viewAreaToggleEditMode.setVisibility(View.VISIBLE);
                    }
                    if (tvScrollTitle != null) {
                        if (viewAreaToggleEditMode != null) {
                            tvScrollTitle.setVisibility(View.INVISIBLE);
                        }
                        tvScrollTitle.setText("");
                    }
                }
            }
        }
    });

    FlexibleRecyclerSelectionListener rs = new FlexibleRecyclerSelectionListener<FilesTreeAdapter, FilesAdapterDisplayObject>() {
        @Override
        public void onItemSelected(FilesTreeAdapter adapter, final int position, boolean isChecked) {
        }

        @Override
        public void onItemClick(FilesTreeAdapter adapter, int position) {
            if (AndroidUtils.usesNavigationControl()) {
                FilesAdapterDisplayObject oItem = adapter.getItem(position);
                if (adapter.isInEditMode()) {
                    adapter.flipWant(oItem);
                    return;
                }
                if (oItem instanceof FilesAdapterDisplayFolder) {
                    FilesAdapterDisplayFolder oFolder = (FilesAdapterDisplayFolder) oItem;
                    oFolder.expand = !oFolder.expand;
                    adapter.getFilter().filter("");
                } else {
                    showFileContextMenu();
                }
            }
        }

        @Override
        public boolean onItemLongClick(FilesTreeAdapter adapter, int position) {
            if (AndroidUtils.usesNavigationControl()) {
                if (showFileContextMenu()) {
                    return true;
                }
            }
            return false;
        }

        @Override
        public void onItemCheckedChanged(FilesTreeAdapter adapter, FilesAdapterDisplayObject item,
                boolean isChecked) {

            if (adapter.getCheckedItemCount() == 0) {
                finishActionMode();
            } else {
                // Update the subtitle with file name
                showContextualActions();
            }

            AndroidUtils.invalidateOptionsMenuHC(getActivity(), mActionMode);
        }
    };

    adapter = new FilesTreeAdapter(this.getActivity(), rs);
    adapter.setSessionInfo(sessionInfo);
    adapter.setMultiCheckModeAllowed(false);
    adapter.setCheckOnSelectedAfterMS(100);
    listview.setAdapter(adapter);

    return view;
}

From source file:no.digipost.android.gui.content.UploadActivity.java

private void promtUpload(final File file) {
    final AlertDialog dialog = DialogUtitities
            .getAlertDialogBuilderWithMessageAndTitle(this,
                    getString(R.string.upload_dialog) + file.getName() + "?", getString(R.string.upload))
            .setPositiveButton(R.string.upload, new DialogInterface.OnClickListener() {
                @Override/*from  w w  w.j  a  v  a2  s  . c  om*/
                public void onClick(DialogInterface dialogInterface, int i) {
                    executeUploadTask(file);
                    dialogInterface.dismiss();
                }
            }).setNegativeButton(R.string.abort, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.dismiss();
                }
            }).create();

    dialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialogInterface) {

            Button b = dialog.getButton(AlertDialog.BUTTON_NEUTRAL);
            b.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    previewFile(file);
                }
            });
        }
    });

    dialog.show();
}

From source file:com.brewcrewfoo.performance.fragments.BatteryInfo.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup root, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.battery_info, root, false);

    mbattery_percent = (TextView) view.findViewById(R.id.batt_percent);
    mbattery_volt = (TextView) view.findViewById(R.id.batt_volt);
    mbattery_status = (TextView) view.findViewById(R.id.batt_status);
    mBattIcon = (ImageView) view.findViewById(R.id.batt_icon);

    if (new File(BAT_VOLT_PATH).exists()) {
        int volt = Integer.parseInt(Helpers.readOneLine(BAT_VOLT_PATH));
        if (volt > 5000)
            volt = (int) Math.round(volt / 1000.0);// in microvolts
        mbattery_volt.setText(volt + " mV");
        mBattIcon.setVisibility(ImageView.GONE);
        mbattery_volt.setVisibility(TextView.VISIBLE);
        mbattery_volt.setOnClickListener(new View.OnClickListener() {
            @Override/*w  w w.j ava  2  s  .co m*/
            public void onClick(View view) {
                Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
                if (powerUsageIntent.resolveActivity(context.getPackageManager()) != null)
                    startActivity(powerUsageIntent);
            }
        });
        mbattery_volt.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                mBattIcon.setVisibility(ImageView.VISIBLE);
                mbattery_volt.setVisibility(TextView.GONE);
                return true;
            }
        });
    } else {
        mBattIcon.setVisibility(ImageView.VISIBLE);
        mbattery_volt.setVisibility(TextView.GONE);
        mBattIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                try {
                    Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
                    startActivity(powerUsageIntent);
                } catch (Exception e) {
                }
            }
        });
    }

    SeekBar mBlxSlider = (SeekBar) view.findViewById(R.id.blx_slider);
    if (new File(BLX_PATH).exists()) {
        no_settings = false;
        mBlxSlider.setMax(100);

        mBlxVal = (TextView) view.findViewById(R.id.blx_val);
        mBlxVal.setText(getString(R.string.blx_title) + " " + Helpers.readOneLine(BLX_PATH) + "%");

        mBlxSlider.setProgress(Integer.parseInt(Helpers.readOneLine(BLX_PATH)));
        mBlxSlider.setOnSeekBarChangeListener(this);
        Switch mSetOnBoot = (Switch) view.findViewById(R.id.blx_sob);
        mSetOnBoot.setChecked(mPreferences.getBoolean(BLX_SOB, false));
        mSetOnBoot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton v, boolean checked) {
                final SharedPreferences.Editor editor = mPreferences.edit();
                editor.putBoolean(BLX_SOB, checked);
                if (checked) {
                    editor.putInt(PREF_BLX, Integer.parseInt(Helpers.readOneLine(BLX_PATH)));
                }
                editor.commit();
            }
        });
    } else {
        LinearLayout mpart = (LinearLayout) view.findViewById(R.id.blx_layout);
        mpart.setVisibility(LinearLayout.GONE);
    }
    mFastChargePath = Helpers.fastcharge_path();
    if (mFastChargePath != null) {
        no_settings = false;
        mFastchargeOnBoot = (Switch) view.findViewById(R.id.fastcharge_sob);
        mFastchargeOnBoot.setChecked(
                mPreferences.getBoolean(PREF_FASTCHARGE, Helpers.readOneLine(mFastChargePath).equals("1")));
        mFastchargeOnBoot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton v, boolean checked) {
                mPreferences.edit().putBoolean(PREF_FASTCHARGE, checked).apply();
                final NotificationManager nm = (NotificationManager) context
                        .getSystemService(Context.NOTIFICATION_SERVICE);
                if (checked) {
                    new CMDProcessor().su.runWaitFor("busybox echo 1 > " + mFastChargePath);
                    Notification n = new Notification.Builder(context)
                            .setContentTitle(context.getText(R.string.app_name))
                            .setContentText(context.getText(R.string.fast_charge_notification_title))
                            .setTicker(context.getText(R.string.fast_charge_notification_title))
                            .setSmallIcon(R.drawable.ic_fastcharge).setWhen(System.currentTimeMillis())
                            .getNotification();
                    //n.flags = Notification.FLAG_NO_CLEAR;
                    nm.notify(1337, n);
                } else {
                    new CMDProcessor().su.runWaitFor("busybox echo 0 > " + mFastChargePath);
                    nm.cancel(1337);
                }
            }
        });
    } else {
        LinearLayout mpart = (LinearLayout) view.findViewById(R.id.fastcharge_layout);
        mpart.setVisibility(LinearLayout.GONE);
    }
    if (no_settings) {
        LinearLayout ns = (LinearLayout) view.findViewById(R.id.no_settings);
        ns.setVisibility(LinearLayout.VISIBLE);
    }

    return view;
}

From source file:com.dattasmoon.pebble.plugin.IgnorePreference.java

@Override
protected void onBindDialogView(View view) {

    btnAdd = (Button) view.findViewById(R.id.btnAdd);
    etMatch = (EditText) view.findViewById(R.id.etMatch);
    chkRawRegex = (CheckBox) view.findViewById(R.id.chkRawRegex);
    chkCaseInsensitive = (CheckBox) view.findViewById(R.id.chkCaseInsensitive);
    actvApplications = (AutoCompleteTextView) view.findViewById(R.id.actvApplications);

    spnApplications = (Spinner) view.findViewById(R.id.spnApplications);
    spnMode = (Spinner) view.findViewById(R.id.spnMode);
    lvIgnore = (ListView) view.findViewById(R.id.lvIgnore);
    lvIgnore.setAdapter(arrayAdapter);/*from  w  w  w  .j  a  va2 s. com*/
    lvIgnore.setEmptyView(view.findViewById(android.R.id.empty));
    new LoadAppsTask().execute();

    lvIgnore.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
        @Override
        public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
            AdapterView.AdapterContextMenuInfo contextInfo = (AdapterView.AdapterContextMenuInfo) menuInfo;
            int position = contextInfo.position;
            long id = contextInfo.id;
            // the child view who's info we're viewing (should be equal to v)
            final View v = contextInfo.targetView;
            MenuInflater inflater = new MenuInflater(getContext());
            inflater.inflate(R.menu.preference_ignore_context, menu);

            //we have to do this mess because DialogPreference doesn't allow for onMenuItemSelected or onOptionsItemSelected. Bleh
            menu.findItem(R.id.btnEdit).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    final int arrayPosition = (Integer) v.getTag();
                    final String text = ((TextView) v.findViewById(R.id.tvItem)).getText().toString();
                    JSONArray temp = new JSONArray();
                    for (int i = 0; i < arrayAdapter.getJSONArray().length(); i++) {
                        try {
                            JSONObject ignore = arrayAdapter.getJSONArray().getJSONObject(i);
                            if (i == arrayPosition) {
                                etMatch.setText(ignore.getString("match"));
                                chkRawRegex.setChecked(ignore.getBoolean("raw"));
                                chkCaseInsensitive.setChecked(ignore.optBoolean("insensitive", true));
                                String app = ignore.getString("app");
                                if (app == "-1") {
                                    actvApplications.setText(getContext().getString(R.string.ignore_any));
                                } else {
                                    actvApplications.setText(app);
                                }
                                boolean exclude = ignore.optBoolean("exclude", true);
                                if (exclude) {
                                    spnMode.setSelection(Constants.IgnoreMode.EXCLUDE.ordinal());
                                } else {
                                    spnMode.setSelection(Constants.IgnoreMode.INCLUDE.ordinal());
                                }
                                continue;
                            }

                            temp.put(ignore);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                    arrayAdapter.setJSONArray(temp);

                    arrayAdapter.notifyDataSetChanged();
                    return true;
                }
            });
            menu.findItem(R.id.btnDelete).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());

                    final int arrayPosition = (Integer) v.getTag();
                    final String text = ((TextView) v.findViewById(R.id.tvItem)).getText().toString();
                    builder.setMessage(getContext().getResources().getString(R.string.confirm_delete) + " '"
                            + text + "' ?")
                            .setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {
                                    JSONArray temp = new JSONArray();
                                    for (int i = 0; i < arrayAdapter.getJSONArray().length(); i++) {
                                        if (i == arrayPosition) {
                                            continue;
                                        }
                                        try {
                                            temp.put(arrayAdapter.getJSONArray().getJSONObject(i));
                                        } catch (JSONException e) {
                                            e.printStackTrace();
                                        }
                                    }
                                    arrayAdapter.setJSONArray(temp);

                                    arrayAdapter.notifyDataSetChanged();
                                }
                            }).setNegativeButton(R.string.decline, new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {
                                    // User cancelled the dialog
                                }
                            });
                    builder.create().show();
                    return true;
                }
            });
        }
    });
    btnAdd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            JSONObject item = new JSONObject();
            try {
                item.put("match", etMatch.getText().toString());
                item.put("raw", chkRawRegex.isChecked());
                item.put("insensitive", chkCaseInsensitive.isChecked());
                if (actvApplications.getText().toString()
                        .equalsIgnoreCase(getContext().getString(R.string.ignore_any))) {
                    item.put("app", "-1");
                } else {
                    item.put("app", actvApplications.getText().toString());
                }
                if (spnMode.getSelectedItemPosition() == Constants.IgnoreMode.INCLUDE.ordinal()) {
                    item.put("exclude", false);
                } else {
                    item.put("exclude", true);
                }
                if (Constants.IS_LOGGABLE) {
                    Log.i(Constants.LOG_TAG, "Item is: " + item.toString());
                }
                arrayAdapter.getJSONArray().put(item);
                etMatch.setText("");
                arrayAdapter.notifyDataSetChanged();
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
    });
    actvApplications.setText(getContext().getString(R.string.ignore_any));
    actvApplications.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            actvApplications.showDropDown();
        }
    });
    actvApplications.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ApplicationInfo pkg = (ApplicationInfo) parent.getItemAtPosition(position);
            if (pkg == null) {
                actvApplications.setText(getContext().getString(R.string.ignore_any));
            } else {
                actvApplications.setText(pkg.packageName);
            }
        }
    });
    actvApplications.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                actvApplications.showDropDown();
            } else {
                if (actvApplications.getText().length() == 0) {
                    actvApplications.setText(getContext().getString(R.string.ignore_any));
                }
            }
        }
    });
    super.onBindDialogView(view);

}

From source file:org.quantumbadger.redreader.fragments.CommentListingFragment.java

public CommentListingFragment(final AppCompatActivity parent, final Bundle savedInstanceState,
        final ArrayList<RedditURLParser.RedditURL> urls, final UUID session, final String searchString,
        final boolean forceDownload) {

    super(parent, savedInstanceState);

    if (savedInstanceState != null) {
        mPreviousFirstVisibleItemPosition = savedInstanceState.getInt(SAVEDSTATE_FIRST_VISIBLE_POS);
    }/*  w  ww .j a v  a  2s  . c  o  m*/

    mCommentListingManager = new FilteredCommentListingManager(parent, searchString);
    mAllUrls = urls;

    mUrlsToDownload = new LinkedList<>(mAllUrls);

    this.mSession = session;

    if (forceDownload) {
        mDownloadStrategy = DownloadStrategyAlways.INSTANCE;

    } else {
        mDownloadStrategy = DownloadStrategyIfNotCached.INSTANCE;
    }

    mUser = RedditAccountManager.getInstance(getActivity()).getDefaultAccount();

    parent.invalidateOptionsMenu();

    final Context context = getActivity();

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    mCommentFontScale = PrefsUtility.appearance_fontscale_comments(context, prefs);
    mShowLinkButtons = PrefsUtility.pref_appearance_linkbuttons(context, prefs);

    mOuterFrame = new FrameLayout(context);

    final ScrollbarRecyclerViewManager recyclerViewManager = new ScrollbarRecyclerViewManager(context, null,
            false);

    if (parent instanceof OptionsMenuUtility.OptionsMenuCommentsListener
            && PrefsUtility.pref_behaviour_enable_swipe_refresh(context, prefs)) {

        recyclerViewManager.enablePullToRefresh(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                ((OptionsMenuUtility.OptionsMenuCommentsListener) parent).onRefreshComments();
            }
        });
    }

    mRecyclerView = recyclerViewManager.getRecyclerView();
    mCommentListingManager.setLayoutManager((LinearLayoutManager) mRecyclerView.getLayoutManager());

    mRecyclerView.setAdapter(mCommentListingManager.getAdapter());
    mOuterFrame.addView(recyclerViewManager.getOuterView());

    mRecyclerView.setItemAnimator(null);

    /* TODO
    {
       final RecyclerView.ItemAnimator itemAnimator = mRecyclerView.getItemAnimator();
       itemAnimator.setRemoveDuration(80);
       itemAnimator.setChangeDuration(80);
       itemAnimator.setAddDuration(80);
       itemAnimator.setMoveDuration(80);
    }
    */

    if (!PrefsUtility.pref_appearance_comments_show_floating_toolbar(context, prefs)) {
        mFloatingToolbar = null;

    } else {
        mFloatingToolbar = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.floating_toolbar,
                mOuterFrame, false);

        // We need a container so that setVisible() doesn't mess with the Z-order
        final FrameLayout floatingToolbarContainer = new FrameLayout(context);

        floatingToolbarContainer.addView(mFloatingToolbar);
        mOuterFrame.addView(floatingToolbarContainer);

        if (PrefsUtility.isNightMode(context)) {
            mFloatingToolbar.setBackgroundColor(Color.argb(0xCC, 0x33, 0x33, 0x33));
        }

        final int buttonVPadding = General.dpToPixels(context, 12);
        final int buttonHPadding = General.dpToPixels(context, 16);

        {
            final ImageButton previousButton = (ImageButton) LayoutInflater.from(context)
                    .inflate(R.layout.flat_image_button, mFloatingToolbar, false);

            previousButton.setPadding(buttonHPadding, buttonVPadding, buttonHPadding, buttonVPadding);
            previousButton.setImageResource(R.drawable.ic_ff_up_dark);
            previousButton.setContentDescription(getString(R.string.button_prev_comment_parent));
            mFloatingToolbar.addView(previousButton);

            previousButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(final View view) {

                    final LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView
                            .getLayoutManager();

                    for (int pos = layoutManager.findFirstVisibleItemPosition() - 1; pos > 0; pos--) {

                        final GroupedRecyclerViewAdapter.Item item = mCommentListingManager
                                .getItemAtPosition(pos);

                        if (item instanceof RedditCommentListItem && ((RedditCommentListItem) item).isComment()
                                && ((RedditCommentListItem) item).getIndent() == 0) {

                            layoutManager.scrollToPositionWithOffset(pos, 0);
                            return;
                        }
                    }

                    layoutManager.scrollToPositionWithOffset(0, 0);
                }
            });

            previousButton.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(final View view) {
                    General.quickToast(context, R.string.button_prev_comment_parent);
                    return true;
                }
            });
        }

        {
            final ImageButton nextButton = (ImageButton) LayoutInflater.from(context)
                    .inflate(R.layout.flat_image_button, mFloatingToolbar, false);

            nextButton.setPadding(buttonHPadding, buttonVPadding, buttonHPadding, buttonVPadding);
            nextButton.setImageResource(R.drawable.ic_ff_down_dark);
            nextButton.setContentDescription(getString(R.string.button_next_comment_parent));
            mFloatingToolbar.addView(nextButton);

            nextButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(final View view) {

                    final LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView
                            .getLayoutManager();

                    for (int pos = layoutManager.findFirstVisibleItemPosition() + 1; pos < layoutManager
                            .getItemCount(); pos++) {

                        final GroupedRecyclerViewAdapter.Item item = mCommentListingManager
                                .getItemAtPosition(pos);

                        if (item instanceof RedditCommentListItem && ((RedditCommentListItem) item).isComment()
                                && ((RedditCommentListItem) item).getIndent() == 0) {

                            layoutManager.scrollToPositionWithOffset(pos, 0);
                            break;
                        }
                    }
                }
            });

            nextButton.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(final View view) {
                    General.quickToast(context, R.string.button_next_comment_parent);
                    return true;
                }
            });
        }
    }

    final SideToolbarOverlay toolbarOverlay = new SideToolbarOverlay(context);

    final BezelSwipeOverlay bezelOverlay = new BezelSwipeOverlay(context,
            new BezelSwipeOverlay.BezelSwipeListener() {
                @Override
                public boolean onSwipe(@BezelSwipeOverlay.SwipeEdge int edge) {

                    if (mPost == null)
                        return false;

                    toolbarOverlay.setContents(mPost.generateToolbar(getActivity(), true, toolbarOverlay));
                    toolbarOverlay
                            .show(edge == BezelSwipeOverlay.LEFT ? SideToolbarOverlay.SideToolbarPosition.LEFT
                                    : SideToolbarOverlay.SideToolbarPosition.RIGHT);
                    return true;
                }

                public boolean onTap() {

                    if (toolbarOverlay.isShown()) {
                        toolbarOverlay.hide();
                        return true;
                    }

                    return false;
                }
            });

    mOuterFrame.addView(bezelOverlay);
    mOuterFrame.addView(toolbarOverlay);

    bezelOverlay.getLayoutParams().width = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;
    bezelOverlay.getLayoutParams().height = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;

    toolbarOverlay.getLayoutParams().width = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;
    toolbarOverlay.getLayoutParams().height = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;

    makeNextRequest(context);
}

From source file:mx.klozz.xperience.tweaker.fragments.BatteryInfo.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup root, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.battery_info, root, false);

    mBattery_Percent = (TextView) view.findViewById(R.id.battery_percent);
    mBattery_volt = (TextView) view.findViewById(R.id.battery_volt);
    mBattery_Status = (TextView) view.findViewById(R.id.battery_status);
    mBatteryIcon = (ImageView) view.findViewById(R.id.battery_icon);

    //Checamos si existe algo relacionado con la direccion de voltajes
    if (new File(BAT_VOLT_PATH).exists()) {
        int volt = Integer.parseInt(Helpers.LeerUnaLinea(BAT_VOLT_PATH));//vemos si existe el directorio
        if (volt > 5000)
            volt = (int) Math.round(volt / 1000.0);//Convertimos a microvolts

        mBattery_volt.setText(volt + " mV");//Hacemos visible los datos
        mBatteryIcon.setVisibility(ImageView.GONE);
        mBattery_volt.setVisibility(TextView.VISIBLE);
        mBattery_volt.setOnClickListener(new View.OnClickListener() {
            @Override//from www  .j a v  a 2 s .c  o  m
            public void onClick(View view) {
                Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
                if (powerUsageIntent.resolveActivity(context.getPackageManager()) != null)
                    startActivity(powerUsageIntent);
            }
        });
        mBattery_volt.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                mBatteryIcon.setVisibility(ImageView.VISIBLE);
                mBattery_volt.setVisibility(TextView.GONE);
                return true;
            }
        });
    } else {
        mBatteryIcon.setVisibility(ImageView.VISIBLE);
        mBattery_volt.setVisibility(TextView.GONE);
        mBatteryIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                try {
                    Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
                    startActivity(powerUsageIntent);
                } catch (Exception e) {
                }
            }
        });
    }

    mFastChargePath = Helpers.fastcharge_path();
    if (mFastChargePath != null) {
        no_settings = false;
        mFastChargeOnBoot = (Switch) view.findViewById(R.id.fastcharge_sob);
        mFastChargeOnBoot.setChecked(
                mPreferences.getBoolean(PREF_FASTCHARGE, Helpers.LeerUnaLinea(mFastChargePath).equals("1")));
        mFastChargeOnBoot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton v, boolean checked) {
                mPreferences.edit().putBoolean(PREF_FASTCHARGE, checked).apply();
                final NotificationManager NM = (NotificationManager) context
                        .getSystemService(Context.NOTIFICATION_SERVICE);
                if (checked) {
                    new CMDProcessor().su.runWaitFor("busybox exho 1 > " + mFastChargePath);
                    Notification N = new Notification.Builder(context)
                            .setContentTitle(context.getText(R.string.app_name))
                            .setContentText(context.getText(R.string.fast_charge_notification_title))
                            .setTicker(context.getText(R.string.fast_charge_notification_title))
                            .setSmallIcon(R.drawable.ic_fastcharge).setWhen(System.currentTimeMillis())
                            .getNotification();
                    NM.notify(1337, N);
                } else {
                    new CMDProcessor().su.runWaitFor("busybox echo 0 > " + mFastChargePath);
                    NM.cancel(1337);

                }
            }

        });
    } else {
        LinearLayout mPart = (LinearLayout) view.findViewById(R.id.fastcharge_layout);
        mPart.setVisibility(LinearLayout.GONE);
    }
    if (no_settings) {
        LinearLayout NS = (LinearLayout) view.findViewById(R.id.no_settings);
        NS.setVisibility(LinearLayout.VISIBLE);
    }
    return view;
}

From source file:uk.ac.hutton.ics.buntata.adapter.DatasourceAdapter.java

@Override
public void onBindViewHolder(final AbstractViewHolder h, final int section, final int relativePosition,
        final int absolutePosition) {
    final BuntataDatasource item;

    final boolean isExpanded = getAbsolutePosition(absolutePosition, section) == expandedPosition;

    switch (section) {
    case LOCAL:/*from w  w  w. j  a v a  2  s  . c o m*/
        item = local.get(relativePosition);
        break;
    case REMOTE:
    default:
        item = remote.get(relativePosition);
    }

    final ItemViewHolder holder = (ItemViewHolder) h;

    holder.nameView.setText(item.getName());
    holder.descriptionView.setText(item.getDescription());
    holder.sizeView.setText(context.getString(R.string.datasource_size, (item.getSizeNoVideo() / 1024f / 1024f),
            (item.getSizeTotal() / 1024f / 1024f)));
    holder.contactView.setText(item.getContact());
    holder.contactView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ShareCompat.IntentBuilder.from(context).setType("message/rfc822").addEmailTo(item.getContact())
                    .setSubject(context.getString(R.string.contact_email_subject))
                    .setChooserTitle(R.string.contact_email_dialog_title).startChooser();
        }
    });

    holder.providerView.setText(item.getDataProvider());
    holder.versionView.setText(Integer.toString(item.getVersionNumber()));

    final BuntataDatasourceAdvanced ds = get(section, relativePosition);
    holder.progressBar.setVisibility(ds.isDownloading() ? View.VISIBLE : View.GONE);

    setState(ds, holder);
    //      holder.downloadStatus.setImageResource(resource);
    //      holder.downloadStatus.setColorFilter(ContextCompat.getColor(context, R.color.colorPrimaryDark));

    /* If there is an icon, set it */
    String iconPath = DatasourceService.getIcon(context, item);
    if (!StringUtils.isEmpty(iconPath)) {
        holder.imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

        RequestCreator r;

        File f = new File(iconPath);
        if (f.exists())
            r = Picasso.get().load(f);
        else
            r = Picasso.get().load(iconPath);

        r.noPlaceholder().into(holder.imageView);
    }
    /* Else set a default icon */
    else {
        holder.imageView.setImageResource(R.drawable.drawer_data_source);
        holder.imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        holder.imageView.setColorFilter(ContextCompat.getColor(context, R.color.colorPrimaryDark));
    }

    holder.detailsView.setVisibility(isExpanded ? View.VISIBLE : View.GONE);

    holder.view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            expandedPosition = isExpanded ? -1 : getAbsolutePosition(absolutePosition, section);

            /* Set a new transition */
            ChangeBounds transition = new ChangeBounds();
            /* For 150 ms */
            transition.setDuration(150);
            /* And start it */
            TransitionManager.beginDelayedTransition(parent, transition);

            /* Let the parent view know that something changed and that it needs to re-layout */
            notifyDataSetChanged();
        }
    });

    /* Add a long click handler */
    holder.view.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            /* If it's not installed or if it's currently downloading, do nothing */
            if ((ds.getState() == BuntataDatasourceAdvanced.InstallState.NOT_INSTALLED) || ds.isDownloading())
                return true;

            /* Show the option do delete the data source */
            DialogUtils.showDialog(context, R.string.dialog_delete_datasource_title,
                    R.string.dialog_delete_datasource_text, R.string.generic_yes, R.string.generic_no,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            /* Reset the currently selected data source, if this was the selected item */
                            int selected = PreferenceUtils.getPreferenceAsInt(context,
                                    PreferenceUtils.PREFS_SELECTED_DATASOURCE_ID, -1);
                            if (selected == ds.getId())
                                PreferenceUtils.removePreference(context,
                                        PreferenceUtils.PREFS_SELECTED_DATASOURCE_ID);

                            /* Remember that this isn't downloaded anymore */
                            ds.setState(BuntataDatasourceAdvanced.InstallState.NOT_INSTALLED);

                            try {
                                /* Delete associated files */
                                new DatasourceManager(context, ds.getId()).remove();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }

                            int installedDatasources = new DatasourceManager(context, -1).getAll().size();

                            if (installedDatasources < 1)
                                PreferenceUtils.removePreference(context,
                                        PreferenceUtils.PREFS_AT_LEAST_ONE_DATASOURCE);

                            onDatasetChanged();
                            animate(holder);

                            GoogleAnalyticsUtils.trackEvent(context,
                                    BaseActivity.getTracker(context, BaseActivity.TrackerName.APP_TRACKER),
                                    context.getString(R.string.ga_event_category_datasource_deleted),
                                    "Datasource: " + ds.getId());
                        }
                    }, null);
            return true;
        }
    });

    /* Add a click handler */
    holder.downloadStatus.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (ds.isDownloading()) {

                DialogUtils.showDialog(context, R.string.dialog_download_cancel_title,
                        R.string.dialog_download_cancel_text, R.string.generic_yes, R.string.generic_no,
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                if (downloadTask != null) {
                                    downloadTask.cancel(true);
                                    holder.progressBar.setVisibility(View.GONE);
                                    ds.setDownloading(false);
                                    downloadTask = null;
                                    setState(ds, holder);
                                }
                            }
                        }, null);
                return;
            } else {
                for (BuntataDatasourceAdvanced dss : dataset) {
                    if (dss.isDownloading()) {
                        SnackbarUtils.show(v, R.string.snackbar_only_one_download,
                                ContextCompat.getColor(context, android.R.color.primary_text_dark),
                                ContextCompat.getColor(context, R.color.colorPrimaryDark),
                                Snackbar.LENGTH_LONG);
                        return;
                    }
                }
            }

            switch (ds.getState()) {
            case INSTALLED_NO_UPDATE:
                /* Just remember the selected id and close the activity to return to wherever we came from */
                PreferenceUtils.setPreferenceAsInt(context, PreferenceUtils.PREFS_SELECTED_DATASOURCE_ID,
                        ds.getId());
                context.setResult(Activity.RESULT_OK);
                context.finish();
                return;

            case INSTALLED_HAS_UPDATE:
            case NOT_INSTALLED:

                DialogUtils.showDialog(context, R.string.dialog_download_title,
                        R.string.dialog_download_message, R.string.generic_yes, R.string.generic_no,
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                initDownload(true, holder, ds);
                            }
                        }, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                initDownload(false, holder, ds);
                            }
                        });
                break;
            }
        }
    });
}

From source file:net.kourlas.voipms_sms.activities.ConversationActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.conversation);

    database = Database.getInstance(getApplicationContext());
    preferences = Preferences.getInstance(getApplicationContext());

    contact = getIntent().getStringExtra(getString(R.string.conversation_extra_contact));
    // Remove the leading one from a North American phone number (e.g. +1 (123) 555-4567)
    if ((contact.length() == 11) && (contact.charAt(0) == '1')) {
        contact = contact.substring(1);//  w ww .  j  av a 2 s . c  o m
    }

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    ViewCompat.setElevation(toolbar, getResources().getDimension(R.dimen.toolbar_elevation));
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        String contactName = Utils.getContactName(this, contact);
        if (contactName != null) {
            actionBar.setTitle(contactName);
        } else {
            actionBar.setTitle(Utils.getFormattedPhoneNumber(contact));
        }
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    layoutManager = new LinearLayoutManager(this);
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    layoutManager.setStackFromEnd(true);
    adapter = new ConversationRecyclerViewAdapter(this, layoutManager, contact);
    recyclerView = (RecyclerView) findViewById(R.id.list);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(adapter);

    actionMode = null;
    actionModeEnabled = false;

    final EditText messageText = (EditText) findViewById(R.id.message_edit_text);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        messageText.setOutlineProvider(new ViewOutlineProvider() {
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), 15);
            }
        });
        messageText.setClipToOutline(true);
    }
    messageText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // Do nothing.
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // Do nothing.
        }

        @Override
        public void afterTextChanged(Editable s) {
            ViewSwitcher viewSwitcher = (ViewSwitcher) findViewById(R.id.view_switcher);
            if (s.toString().equals("") && viewSwitcher.getDisplayedChild() == 1) {
                viewSwitcher.setDisplayedChild(0);
            } else if (viewSwitcher.getDisplayedChild() == 0) {
                viewSwitcher.setDisplayedChild(1);
            }
        }
    });
    messageText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                adapter.refresh();
            }
        }
    });
    String intentMessageText = getIntent().getStringExtra(getString(R.string.conversation_extra_message_text));
    if (intentMessageText != null) {
        messageText.setText(intentMessageText);
    }
    boolean intentFocus = getIntent().getBooleanExtra(getString(R.string.conversation_extra_focus), false);
    if (intentFocus) {
        messageText.requestFocus();
    }

    RelativeLayout messageSection = (RelativeLayout) findViewById(R.id.message_section);
    ViewCompat.setElevation(messageSection, 8);

    QuickContactBadge photo = (QuickContactBadge) findViewById(R.id.photo);
    Utils.applyCircularMask(photo);
    photo.assignContactFromPhone(preferences.getDid(), true);
    String photoUri = Utils.getContactPhotoUri(getApplicationContext(), preferences.getDid());
    if (photoUri != null) {
        photo.setImageURI(Uri.parse(photoUri));
    } else {
        photo.setImageToDefault();
    }

    final ImageButton sendButton = (ImageButton) findViewById(R.id.send_button);
    Utils.applyCircularMask(sendButton);
    sendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            preSendMessage();
        }
    });
}