Search in sources :

Example 96 with START

use of android.support.v7.widget.helper.ItemTouchHelper.START in project quran_android by quran.

the class JumpFragment method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Activity activity = getActivity();
    LayoutInflater inflater = activity.getLayoutInflater();
    @SuppressLint("InflateParams") View layout = inflater.inflate(R.layout.jump_dialog, null);
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(activity.getString(R.string.menu_jump));
    // Sura chooser
    final ForceCompleteTextView suraInput = (ForceCompleteTextView) layout.findViewById(R.id.sura_spinner);
    final String[] suras = activity.getResources().getStringArray(R.array.sura_names);
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < suras.length; i++) {
        sb.append(QuranUtils.getLocalizedNumber(activity, (i + 1)));
        sb.append(". ");
        sb.append(suras[i]);
        suras[i] = sb.toString();
        sb.setLength(0);
    }
    InfixFilterArrayAdapter suraAdapter = new InfixFilterArrayAdapter(activity, android.R.layout.simple_spinner_dropdown_item, suras);
    suraInput.setAdapter(suraAdapter);
    // Ayah chooser
    final EditText ayahInput = (EditText) layout.findViewById(R.id.ayah_spinner);
    // Page chooser
    final EditText pageInput = (EditText) layout.findViewById(R.id.page_number);
    pageInput.setOnEditorActionListener((v, actionId, event) -> {
        boolean handled = false;
        if (actionId == EditorInfo.IME_ACTION_GO) {
            dismiss();
            goToPage(pageInput.getText().toString());
            handled = true;
        }
        return handled;
    });
    suraInput.setOnForceCompleteListener((v, position, rowId) -> {
        List<String> suraList = Arrays.asList(suras);
        String enteredText = suraInput.getText().toString();
        String suraName;
        if (position >= 0) {
            // user selects
            suraName = suraAdapter.getItem(position);
        } else if (suraList.contains(enteredText)) {
            suraName = enteredText;
        } else if (suraAdapter.isEmpty()) {
            // leave to the next code
            suraName = null;
        } else {
            // maybe first initialization or invalid input
            suraName = suraAdapter.getItem(0);
        }
        int sura = suraList.indexOf(suraName) + 1;
        if (sura == 0)
            // default to al-Fatiha
            sura = 1;
        suraInput.setTag(sura);
        suraInput.setText(suras[sura - 1]);
        // trigger ayah change
        CharSequence ayahValue = ayahInput.getText();
        // space is intentional, to differentiate with value set by the user (delete/backspace)
        ayahInput.setText(ayahValue.length() > 0 ? ayahValue : " ");
    });
    ayahInput.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

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

        @Override
        public void afterTextChanged(Editable s) {
            Context context = getActivity();
            String ayahString = s.toString();
            int ayah = parseInt(ayahString, 1);
            Object suraTag = suraInput.getTag();
            if (suraTag != null) {
                int sura = (int) suraTag;
                int ayahCount = quranInfo.getNumAyahs(sura);
                // ensure in 1..ayahCount
                ayah = Math.max(1, Math.min(ayahCount, ayah));
                int page = quranInfo.getPageFromSuraAyah(sura, ayah);
                pageInput.setHint(QuranUtils.getLocalizedNumber(context, page));
                pageInput.setText(null);
            }
            ayahInput.setTag(ayah);
            // seems numeric IM always use western arabic (not localized)
            String correctText = String.valueOf(ayah);
            // empty input means the user clears the input, we don't force to fill it, let him type
            if (s.length() > 0 && !correctText.equals(ayahString)) {
                s.replace(0, s.length(), correctText);
            }
        }
    });
    builder.setView(layout);
    builder.setPositiveButton(getString(R.string.dialog_ok), (dialog, which) -> {
        try {
            dismiss();
            String pageStr = pageInput.getText().toString();
            if (TextUtils.isEmpty(pageStr)) {
                pageStr = pageInput.getHint().toString();
                int page = Integer.parseInt(pageStr);
                int selectedSura = (int) suraInput.getTag();
                int selectedAyah = (int) ayahInput.getTag();
                if (activity instanceof JumpDestination) {
                    ((JumpDestination) activity).jumpToAndHighlight(page, selectedSura, selectedAyah);
                }
            } else {
                goToPage(pageStr);
            }
        } catch (Exception e) {
            Timber.d(e, "Could not jump, something went wrong...");
        }
    });
    return builder.create();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) EditText(android.widget.EditText) Context(android.content.Context) Activity(android.app.Activity) View(android.view.View) ForceCompleteTextView(com.quran.labs.androidquran.widgets.ForceCompleteTextView) TextView(android.widget.TextView) ForceCompleteTextView(com.quran.labs.androidquran.widgets.ForceCompleteTextView) SuppressLint(android.annotation.SuppressLint) LayoutInflater(android.view.LayoutInflater) SuppressLint(android.annotation.SuppressLint) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) JumpDestination(com.quran.labs.androidquran.ui.helpers.JumpDestination) NonNull(android.support.annotation.NonNull)

Example 97 with START

use of android.support.v7.widget.helper.ItemTouchHelper.START in project incubator-weex by apache.

the class UpdateService method handleActionUpdate.

private void handleActionUpdate(String url) {
    manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    builder = new NotificationCompat.Builder(this);
    builder.setContentTitle(CheckForUpdateUtil.getStringRes(R.string.update_downloading)).setContentText(CheckForUpdateUtil.getStringRes(R.string.update_progress) + " 0%").setTicker(CheckForUpdateUtil.getStringRes(R.string.update_downloading)).setWhen(System.currentTimeMillis()).setPriority(Notification.PRIORITY_DEFAULT).setSmallIcon(R.mipmap.ic_launcher).setProgress(100, 0, false);
    manager.notify(NOTIFY_ID, builder.build());
    WXLogUtils.e("Update", "start download");
    Downloader.download(url, new Downloader.DownloadCallback(getCacheDir().getAbsolutePath(), "playground.apk") {

        @Override
        public void onProgress(float progress) {
            if (progress * 100 - progress >= 1) {
                int p = (int) (progress * 100);
                builder.setContentText(CheckForUpdateUtil.getStringRes(R.string.update_progress) + p + "%");
                builder.setProgress(100, p, false);
                manager.notify(NOTIFY_ID, builder.build());
                WXLogUtils.d("Update", "progress:" + p);
            }
        }

        @Override
        public void onResponse(File file) {
            WXLogUtils.d("Update", "success: " + file.getAbsolutePath());
            manager.cancel(NOTIFY_ID);
            Uri uri = Uri.fromFile(file);
            Intent installIntent = new Intent(Intent.ACTION_VIEW);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                installIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                Uri contentUri = FileProvider.getUriForFile(WXEnvironment.getApplication(), BuildConfig.APPLICATION_ID + ".fileprovider", file);
                installIntent.setDataAndType(contentUri, "application/vnd.android.package-archive");
            } else {
                installIntent.setDataAndType(uri, "application/vnd.android.package-archive");
                installIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            }
            startActivity(installIntent);
        }

        @Override
        public void onError(final Exception e) {
            WXSDKManager.getInstance().getWXRenderManager().postOnUiThread(new Runnable() {

                @Override
                public void run() {
                    Toast.makeText(UpdateService.this, "Failed to update:" + e.getMessage(), Toast.LENGTH_SHORT).show();
                }
            }, 0);
        }
    });
}
Also used : NotificationCompat(android.support.v7.app.NotificationCompat) Intent(android.content.Intent) File(java.io.File) Uri(android.net.Uri)

Example 98 with START

use of android.support.v7.widget.helper.ItemTouchHelper.START in project Camera-Roll-Android-App by kollerlukas.

the class FileExplorerActivity method onDataChanged.

@Override
public void onDataChanged() {
    final View emptyState = findViewById(R.id.empty_state_text);
    emptyState.animate().alpha(currentDir.getChildren().size() == 0 ? 1.0f : 0.0f).setListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            emptyState.setVisibility(currentDir.getChildren().size() == 0 ? View.VISIBLE : View.GONE);
        }
    }).setDuration(100).start();
    if (recyclerViewAdapter.getMode() == FileExplorerAdapter.NORMAL_MODE) {
        final Toolbar toolbar = findViewById(R.id.toolbar);
        ColorFade.fadeToolbarTitleColor(toolbar, textColorPrimary, new ColorFade.ToolbarTitleFadeCallback() {

            @Override
            public void setTitle(Toolbar toolbar) {
                toolbar.setTitle(currentDir.getPath());
            }
        });
    }
    if (recyclerViewAdapter.getMode() == FileExplorerAdapter.NORMAL_MODE) {
        manageMenuItems();
    }
}
Also used : ColorFade(us.koller.cameraroll.util.animators.ColorFade) Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) Toolbar(android.support.v7.widget.Toolbar)

Example 99 with START

use of android.support.v7.widget.helper.ItemTouchHelper.START in project Camera-Roll-Android-App by kollerlukas.

the class FileExplorerActivity method onSelectorModeEnter.

@Override
public void onSelectorModeEnter() {
    fileOpIntent = null;
    final Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setActivated(true);
    toolbar.animate().translationY(0.0f).start();
    if (theme.darkStatusBarIconsInSelectorMode()) {
        Util.setDarkStatusBarIcons(findViewById(R.id.root_view));
    } else {
        Util.setLightStatusBarIcons(findViewById(R.id.root_view));
    }
    ColorDrawable statusBarOverlay = getStatusBarOverlay();
    if (statusBarOverlay != null) {
        ColorFade.fadeDrawableAlpha(statusBarOverlay, 0);
    }
    ColorFade.fadeBackgroundColor(toolbar, toolbarColor, accentColor);
    ColorFade.fadeToolbarTitleColor(toolbar, accentTextColor, null);
    // fade overflow menu icon
    ColorFade.fadeDrawableColor(toolbar.getOverflowIcon(), textColorSecondary, accentTextColor);
    Drawable navIcon = toolbar.getNavigationIcon();
    if (navIcon instanceof Animatable) {
        ((Animatable) navIcon).start();
        ColorFade.fadeDrawableColor(navIcon, textColorSecondary, accentTextColor);
    }
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            Drawable d;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                AnimatedVectorDrawable drawable = (AnimatedVectorDrawable) ContextCompat.getDrawable(FileExplorerActivity.this, R.drawable.cancel_to_back_avd);
                // mutating avd to reset it
                drawable.mutate();
                d = drawable;
            } else {
                d = ContextCompat.getDrawable(FileExplorerActivity.this, R.drawable.ic_clear_white);
            }
            d = DrawableCompat.wrap(d);
            DrawableCompat.setTint(d.mutate(), accentTextColor);
            toolbar.setNavigationIcon(d);
            // make menu items visible
            for (int i = 0; i < menu.size(); i++) {
                MenuItem item = menu.getItem(i);
                switch(item.getItemId()) {
                    case R.id.copy:
                    case R.id.move:
                    case R.id.delete:
                        item.setVisible(true);
                        break;
                    default:
                        item.setVisible(false);
                        break;
                }
            }
        }
    }, navIcon instanceof Animatable ? (int) (500 * Util.getAnimatorSpeed(this)) : 0);
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable) Animatable(android.graphics.drawable.Animatable) Handler(android.os.Handler) MenuItem(android.view.MenuItem) Toolbar(android.support.v7.widget.Toolbar) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable)

Example 100 with START

use of android.support.v7.widget.helper.ItemTouchHelper.START in project Camera-Roll-Android-App by kollerlukas.

the class MainActivity method onActivityReenter.

@Override
public void onActivityReenter(final int resultCode, Intent intent) {
    super.onActivityReenter(resultCode, intent);
    int nestedRecyclerViewValue = getResources().getInteger(R.integer.STYLE_NESTED_RECYCLER_VIEW_VALUE);
    if (intent.getAction() != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && intent.getAction().equals(ItemActivity.SHARED_ELEMENT_RETURN_TRANSITION) && Settings.getInstance(this).getStyle(this, pick_photos) == nestedRecyclerViewValue) {
        // handle shared-element transition, for nested nestedRecyclerView style
        Bundle tmpReenterState = new Bundle(intent.getExtras());
        if (tmpReenterState.containsKey(AlbumActivity.ALBUM_PATH) && tmpReenterState.containsKey(AlbumActivity.EXTRA_CURRENT_ALBUM_POSITION)) {
            String albumPath = tmpReenterState.getString(AlbumActivity.ALBUM_PATH);
            final int sharedElementReturnPosition = tmpReenterState.getInt(AlbumActivity.EXTRA_CURRENT_ALBUM_POSITION);
            int index = -1;
            ArrayList<Album> albums = MediaProvider.getAlbumsWithVirtualDirectories(this);
            for (int i = 0; i < albums.size(); i++) {
                if (albums.get(i).getPath().equals(albumPath)) {
                    index = i;
                    break;
                }
            }
            if (index == -1) {
                return;
            }
            // postponing transition until sharedElement is laid out
            postponeEnterTransition();
            setExitSharedElementCallback(mCallback);
            final NestedRecyclerViewAlbumHolder.StartSharedElementTransitionCallback callback = new NestedRecyclerViewAlbumHolder.StartSharedElementTransitionCallback() {

                @Override
                @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
                public void startPostponedEnterTransition() {
                    // sharedElement is laid out --> start transition
                    MainActivity.this.startPostponedEnterTransition();
                }
            };
            final int finalIndex = index;
            recyclerView.scrollToPosition(index);
            // wait until ViewHolder is laid out
            recyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {

                @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
                @Override
                public void onLayoutChange(View v, int l, int t, int r, int b, int oL, int oT, int oR, int oB) {
                    RecyclerView.ViewHolder viewHolder = recyclerView.findViewHolderForAdapterPosition(finalIndex);
                    if (viewHolder != null) {
                        recyclerView.removeOnLayoutChangeListener(this);
                    } else {
                        // viewHolder hasn't been laid out yet --> wait
                        recyclerView.scrollToPosition(finalIndex);
                    }
                    if (viewHolder instanceof NestedRecyclerViewAlbumHolder) {
                        // found ViewHolder
                        sharedElementViewHolder = (NestedRecyclerViewAlbumHolder) viewHolder;
                        ((NestedRecyclerViewAlbumHolder) viewHolder).onSharedElement(sharedElementReturnPosition, callback);
                    }
                }
            });
        }
    }
}
Also used : NestedRecyclerViewAlbumHolder(us.koller.cameraroll.adapter.main.viewHolder.NestedRecyclerViewAlbumHolder) Bundle(android.os.Bundle) Album(us.koller.cameraroll.data.models.Album) View(android.view.View) FastScrollerRecyclerView(us.koller.cameraroll.ui.widget.FastScrollerRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) ParallaxImageView(us.koller.cameraroll.ui.widget.ParallaxImageView) RequiresApi(android.support.annotation.RequiresApi)

Aggregations

View (android.view.View)367 RecyclerView (android.support.v7.widget.RecyclerView)271 TextView (android.widget.TextView)175 Intent (android.content.Intent)109 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)84 Toolbar (android.support.v7.widget.Toolbar)77 TextWatcher (android.text.TextWatcher)77 Editable (android.text.Editable)76 ImageView (android.widget.ImageView)76 ArrayList (java.util.ArrayList)68 Bundle (android.os.Bundle)48 DialogInterface (android.content.DialogInterface)47 AlertDialog (android.support.v7.app.AlertDialog)47 AdapterView (android.widget.AdapterView)46 EditText (android.widget.EditText)42 SuppressLint (android.annotation.SuppressLint)39 Button (android.widget.Button)39 ActionBar (android.support.v7.app.ActionBar)34 List (java.util.List)34 ViewPropertyAnimatorCompat (android.support.v4.view.ViewPropertyAnimatorCompat)33