Search in sources :

Example 26 with UP

use of android.support.v7.widget.helper.ItemTouchHelper.UP in project Shuttle by timusus.

the class MainActivity method onCreate.

@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
    if (!ShuttleUtils.isUpgraded() && !ShuttleUtils.isAmazonBuild()) {
        IabManager.getInstance();
    }
    ThemeUtils.setTheme(this);
    if (!ShuttleUtils.hasLollipop() && ShuttleUtils.hasKitKat()) {
        getWindow().setFlags(FLAG_TRANSLUCENT_STATUS, FLAG_TRANSLUCENT_STATUS);
        mTintManager = new SystemBarTintManager(this);
    }
    if (ShuttleUtils.hasLollipop()) {
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        getWindow().setStatusBarColor(Color.TRANSPARENT);
    }
    if (SettingsManager.getInstance().canTintNavBar()) {
        getWindow().setNavigationBarColor(ColorUtils.getPrimaryColorDark(this));
    }
    supportRequestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    // Now call super to ensure the theme was properly set
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mIsSlidingEnabled = getResources().getBoolean(R.bool.isSlidingEnabled);
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mDummyStatusBar = (FrameLayout) findViewById(R.id.dummyStatusBar);
    if (ShuttleUtils.hasKitKat()) {
        mDummyStatusBar.setVisibility(View.VISIBLE);
        mDummyStatusBar.setBackgroundColor(ColorUtils.getPrimaryColorDark(this));
        LinearLayout.LayoutParams statusBarParams = new LinearLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, (int) ActionBarUtils.getStatusBarHeight(this));
        mDummyStatusBar.setLayoutParams(statusBarParams);
    }
    setSupportActionBar(mToolbar);
    ThemeUtils.themeStatusBar(this, mTintManager);
    mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
    mTitle = getString(R.string.library_title);
    mDrawerLayout = (CustomDrawerLayout) findViewById(R.id.drawer_layout);
    if (ShuttleUtils.hasLollipop() && ShuttleUtils.hasKitKat()) {
        getWindow().setStatusBarColor(Color.TRANSPARENT);
    }
    mDrawerLayout.setStatusBarBackgroundColor(ShuttleUtils.hasLollipop() ? ColorUtils.getPrimaryColorDark(this) : ColorUtils.getPrimaryColor());
    mNavigationDrawerFragment.setup((DrawerLayout) findViewById(R.id.drawer_layout));
    if (mIsSlidingEnabled) {
        mSlidingUpPanelLayout = (SlidingUpPanelLayout) findViewById(R.id.container);
        setDragView(null, false);
        //The second panel slide offset is mini player height + toolbar height + status bar height.
        //This gets our 'up next' sitting snugly underneath the toolbar
        int offset = (int) (ActionBarUtils.getActionBarHeight(this) + (ShuttleUtils.hasKitKat() ? ActionBarUtils.getStatusBarHeight(this) : 0) - getResources().getDimension(R.dimen.mini_player_height));
        mSlidingUpPanelLayout.setSlidePanelOffset(-offset);
        mSlidingUpPanelLayout.hidePanel();
        mSlidingUpPanelLayout.addPanelSlideListener(new SlidingUpPanelLayout.PanelSlideListener() {

            @Override
            public void onPanelSlide(View panel, float slideOffset) {
                setActionBarAlpha(slideOffset, false);
                boolean canChangeElevation = true;
                Fragment playingFragment = getSupportFragmentManager().findFragmentById(R.id.player_container);
                if (playingFragment != null) {
                    Fragment childFragment = playingFragment.getChildFragmentManager().findFragmentById(R.id.queue_container);
                    if (childFragment != null && childFragment instanceof QueueFragment) {
                        canChangeElevation = false;
                    }
                }
                if (canChangeElevation) {
                    getSupportActionBar().setElevation(ResourceUtils.toPixels(4) * slideOffset);
                }
                mNavigationDrawerFragment.animateDrawerToggle(slideOffset);
            }

            @Override
            public void onPanelStateChanged(View panel, SlidingUpPanelLayout.PanelState previousState, SlidingUpPanelLayout.PanelState newState) {
                switch(newState) {
                    case COLLAPSED:
                        {
                            setDragView(null, false);
                            mTitle = getString(R.string.library_title);
                            supportInvalidateOptionsMenu();
                            toggleQueue(false);
                            mNavigationDrawerFragment.toggleDrawerLock(false);
                            break;
                        }
                    case EXPANDED:
                        {
                            Fragment playerFragment = getSupportFragmentManager().findFragmentById(R.id.player_container);
                            if (playerFragment != null && playerFragment instanceof PlayerFragment) {
                                setDragView(((PlayerFragment) playerFragment).getDragView(), true);
                                if (((PlayerFragment) playerFragment).isQueueShowing()) {
                                    toggleQueue(true);
                                }
                            }
                            mTitle = getString(R.string.nowplaying_title);
                            supportInvalidateOptionsMenu();
                            mNavigationDrawerFragment.toggleDrawerLock(true);
                            break;
                        }
                }
            }
        });
    }
    if (savedInstanceState != null && mIsSlidingEnabled) {
        if (savedInstanceState.getBoolean(ARG_EXPANDED, false)) {
            final ActionBar actionBar = getSupportActionBar();
            //If the sliding panel was previously expanded, expand it again.
            mSlidingUpPanelLayout.post(() -> {
                mSlidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED, false);
                setActionBarAlpha(1f, false);
            });
            mTitle = getString(R.string.nowplaying_title);
            if (actionBar != null) {
                actionBar.setTitle(mTitle);
            }
            Fragment playingFragment = getSupportFragmentManager().findFragmentById(R.id.player_container);
            if (playingFragment != null) {
                Fragment childFragment = playingFragment.getChildFragmentManager().findFragmentById(R.id.queue_container);
                if (childFragment != null && childFragment instanceof QueueFragment) {
                    toggleQueue(true);
                }
            }
        }
    }
    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction().add(R.id.main_container, MainFragment.newInstance()).commit();
        getSupportFragmentManager().beginTransaction().add(R.id.mini_player_container, MiniPlayerFragment.newInstance()).commit();
        if (mIsSlidingEnabled) {
            getSupportFragmentManager().beginTransaction().add(R.id.player_container, PlayerFragment.newInstance()).commit();
        }
    }
    themeTaskDescription();
    handleIntent(getIntent());
}
Also used : SlidingUpPanelLayout(com.sothree.slidinguppanel.SlidingUpPanelLayout) SystemBarTintManager(com.readystatesoftware.systembartint.SystemBarTintManager) QueueFragment(com.simplecity.amp_library.ui.fragments.QueueFragment) View(android.view.View) FolderFragment(com.simplecity.amp_library.ui.fragments.FolderFragment) Fragment(android.support.v4.app.Fragment) QueuePagerFragment(com.simplecity.amp_library.ui.fragments.QueuePagerFragment) PlayerFragment(com.simplecity.amp_library.ui.fragments.PlayerFragment) QueueFragment(com.simplecity.amp_library.ui.fragments.QueueFragment) AlbumArtistFragment(com.simplecity.amp_library.ui.fragments.AlbumArtistFragment) NavigationDrawerFragment(com.simplecity.amp_library.ui.fragments.NavigationDrawerFragment) PlaylistFragment(com.simplecity.amp_library.ui.fragments.PlaylistFragment) GenreFragment(com.simplecity.amp_library.ui.fragments.GenreFragment) DetailFragment(com.simplecity.amp_library.ui.fragments.DetailFragment) SuggestedFragment(com.simplecity.amp_library.ui.fragments.SuggestedFragment) MainFragment(com.simplecity.amp_library.ui.fragments.MainFragment) AlbumFragment(com.simplecity.amp_library.ui.fragments.AlbumFragment) MiniPlayerFragment(com.simplecity.amp_library.ui.fragments.MiniPlayerFragment) SuppressLint(android.annotation.SuppressLint) LinearLayout(android.widget.LinearLayout) ActionBar(android.support.v7.app.ActionBar) PlayerFragment(com.simplecity.amp_library.ui.fragments.PlayerFragment) MiniPlayerFragment(com.simplecity.amp_library.ui.fragments.MiniPlayerFragment) SuppressLint(android.annotation.SuppressLint)

Example 27 with UP

use of android.support.v7.widget.helper.ItemTouchHelper.UP in project Shuttle by timusus.

the class ScrollableViewHelper method getScrollableViewScrollPosition.

/**
     * Returns the current scroll position of the scrollable view. If this method returns zero or
     * less, it means at the scrollable view is in a position such as the panel should handle
     * scrolling. If the method returns anything above zero, then the panel will let the scrollable
     * view handle the scrolling
     *
     * @param scrollableView the scrollable view
     * @param isSlidingUp    whether or not the panel is sliding up or down
     * @return the scroll position
     */
public int getScrollableViewScrollPosition(View scrollableView, boolean isSlidingUp) {
    if (scrollableView == null)
        return 0;
    if (scrollableView instanceof ScrollView) {
        if (isSlidingUp) {
            return scrollableView.getScrollY();
        } else {
            ScrollView sv = ((ScrollView) scrollableView);
            View child = sv.getChildAt(0);
            return (child.getBottom() - (sv.getHeight() + sv.getScrollY()));
        }
    } else if (scrollableView instanceof ListView && ((ListView) scrollableView).getChildCount() > 0) {
        ListView lv = ((ListView) scrollableView);
        if (lv.getAdapter() == null)
            return 0;
        if (isSlidingUp) {
            View firstChild = lv.getChildAt(0);
            // Approximate the scroll position based on the top child and the first visible item
            return lv.getFirstVisiblePosition() * firstChild.getHeight() - firstChild.getTop();
        } else {
            View lastChild = lv.getChildAt(lv.getChildCount() - 1);
            // Approximate the scroll position based on the bottom child and the last visible item
            return (lv.getAdapter().getCount() - lv.getLastVisiblePosition() - 1) * lastChild.getHeight() + lastChild.getBottom() - lv.getBottom();
        }
    } else if (scrollableView instanceof RecyclerView && ((RecyclerView) scrollableView).getChildCount() > 0) {
        RecyclerView rv = ((RecyclerView) scrollableView);
        //return a value > 0
        if (rv instanceof NestedScrollBlocker) {
            if (!((NestedScrollBlocker) rv).getBlockScroll()) {
                return 1;
            }
        }
        RecyclerView.LayoutManager lm = rv.getLayoutManager();
        if (rv.getAdapter() == null)
            return 0;
        if (isSlidingUp) {
            View firstChild = rv.getChildAt(0);
            // Approximate the scroll position based on the top child and the first visible item
            return rv.getChildLayoutPosition(firstChild) * lm.getDecoratedMeasuredHeight(firstChild) - lm.getDecoratedTop(firstChild);
        } else {
            View lastChild = rv.getChildAt(rv.getChildCount() - 1);
            // Approximate the scroll position based on the bottom child and the last visible item
            return (rv.getAdapter().getItemCount() - 1) * lm.getDecoratedMeasuredHeight(lastChild) + lm.getDecoratedBottom(lastChild) - rv.getBottom();
        }
    } else {
        return 0;
    }
}
Also used : ListView(android.widget.ListView) ScrollView(android.widget.ScrollView) RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) View(android.view.View) ListView(android.widget.ListView)

Example 28 with UP

use of android.support.v7.widget.helper.ItemTouchHelper.UP in project TourGuide by worker8.

the class NavDrawerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mActivity = this;
    setContentView(R.layout.activity_nav_drawer);
    /* get views from xml */
    mTextView1 = (TextView) findViewById(R.id.item1);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    /* setup toolbar */
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    toolbar.setTitle("Nav Drawer Example");
    mTutorialHandler = TourGuide.init(mActivity).with(TourGuide.Technique.CLICK).setPointer(new Pointer()).setToolTip(new ToolTip().setTitle(null).setDescription("hello world")).setOverlay(new Overlay().setBackgroundColor(Color.parseColor("#66FF0000")));
    final ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.drawer_open_string, R.string.drawer_close_string) {

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            /* We need call playOn only after the drawer is opened,
                   so that TourGuide knows the updated location of the targetted view */
            mTutorialHandler.playOn(mTextView1);
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    mDrawerToggle.syncState();
    /* setup clean up code */
    mTextView1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mTutorialHandler.cleanUp();
            mDrawerLayout.closeDrawers();
        }
    });
    final ViewTreeObserver viewTreeObserver = mTextView1.getViewTreeObserver();
    viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            // make sure this only run once
            mTextView1.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            mDrawerLayout.openDrawer(Gravity.LEFT);
        }
    });
}
Also used : ToolTip(tourguide.tourguide.ToolTip) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) Pointer(tourguide.tourguide.Pointer) Overlay(tourguide.tourguide.Overlay) TextView(android.widget.TextView) View(android.view.View) ViewTreeObserver(android.view.ViewTreeObserver) Toolbar(android.support.v7.widget.Toolbar)

Example 29 with UP

use of android.support.v7.widget.helper.ItemTouchHelper.UP in project AdMoney by ErnestoGonAr.

the class Detalles_Ingresos_Egresos_Activity 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();
    // noinspection SimplifiableIfStatement
    if (id == R.id.action_borrar) {
        if (this.item2.tipo == 0) {
            new AlertDialog.Builder(this).setMessage("Eliminar Registro?").setCancelable(false).setPositiveButton("Si", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    bd.eliminarEgresos(item2.id);
                    onBackPressed();
                }
            }).setNegativeButton("No", null).show();
        } else {
            // egreso
            new AlertDialog.Builder(this).setMessage("Eliminar Registro?").setCancelable(false).setPositiveButton("Si", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    bd.eliminarIngresos(item2.id);
                    onBackPressed();
                }
            }).setNegativeButton("No", null).show();
        }
    }
    if (id == R.id.action_modificar) {
        categoria.setClickable(true);
        cantidad.setEnabled(true);
        fecha.getEditableText();
        cantidad.getEditableText();
        fecha.setEnabled(true);
        // fecha_p.setVisibility(View.VISIBLE);
        descripcion.setEnabled(true);
        // descripcion.getEditableText();
        linearLayout.setVisibility(View.VISIBLE);
        fecha.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                final Calendar mcurrentDate = Calendar.getInstance();
                mYear = mcurrentDate.get(Calendar.YEAR);
                mMonth = mcurrentDate.get(Calendar.MONTH);
                mDay = mcurrentDate.get(Calendar.DAY_OF_MONTH);
                final DatePickerDialog mDatePicker = new DatePickerDialog(Detalles_Ingresos_Egresos_Activity.this, new DatePickerDialog.OnDateSetListener() {

                    public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday) {
                        // TODO Auto-generated method stub
                        /*SimpleDateFormat simpledateformat = new SimpleDateFormat("EEEE");
                        Date date = new Date(selectedyear, selectedmonth, selectedday-1);
                        String dayOfWeek = simpledateformat.format(date);
                        fechaCadena=selectedday+"-"+(selectedmonth+1)+"-"+selectedyear;
                        d.setText(dayOfWeek+"," +fechaCadena);*/
                        fechaCadena = selectedyear + "-" + (selectedmonth + 1) + "-" + selectedday;
                        fecha.setText(fechaCadena);
                    }
                }, mYear, mMonth, mDay);
                mDatePicker.setTitle("Selecciona la fecha");
                mDatePicker.show();
            // date=mDay+"-"+mMonth+"-"+mYear;
            }
        });
    }
    return super.onOptionsItemSelected(item);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) DatePickerDialog(android.app.DatePickerDialog) Calendar(java.util.Calendar) DatePicker(android.widget.DatePicker) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Example 30 with UP

use of android.support.v7.widget.helper.ItemTouchHelper.UP in project collect by opendatakit.

the class MediaLayout method setAVT.

public void setAVT(FormIndex index, String selectionDesignator, TextView text, String audioURI, String imageURI, String videoURI, final String bigImageURI) {
    this.selectionDesignator = selectionDesignator;
    this.index = index;
    viewText = text;
    originalText = text.getText();
    viewText.setId(ViewIds.generateViewId());
    this.videoURI = videoURI;
    // Layout configurations for our elements in the relative layout
    RelativeLayout.LayoutParams textParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams audioParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams imageParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams videoParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    // First set up the audio button
    if (audioURI != null) {
        // An audio file is specified
        audioButton = new AudioButton(getContext(), this.index, this.selectionDesignator, audioURI, player);
        audioButton.setPadding(22, 12, 22, 12);
        audioButton.setBackgroundColor(Color.LTGRAY);
        audioButton.setOnClickListener(this);
        // random ID to be used by the
        audioButton.setId(ViewIds.generateViewId());
    // relative layout.
    } else {
    // No audio file specified, so ignore.
    }
    // Then set up the video button
    if (videoURI != null) {
        // An video file is specified
        videoButton = new AppCompatImageButton(getContext());
        Bitmap b = BitmapFactory.decodeResource(getContext().getResources(), android.R.drawable.ic_media_play);
        videoButton.setImageBitmap(b);
        videoButton.setPadding(22, 12, 22, 12);
        videoButton.setBackgroundColor(Color.LTGRAY);
        videoButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Collect.getInstance().getActivityLogger().logInstanceAction(this, "onClick", "playVideoPrompt" + MediaLayout.this.selectionDesignator, MediaLayout.this.index);
                MediaLayout.this.playVideo();
            }
        });
        videoButton.setId(ViewIds.generateViewId());
    } else {
    // No video file specified, so ignore.
    }
    // Now set up the image view
    String errorMsg = null;
    final int imageId = ViewIds.generateViewId();
    if (imageURI != null) {
        try {
            String imageFilename = ReferenceManager.instance().DeriveReference(imageURI).getLocalURI();
            final File imageFile = new File(imageFilename);
            if (imageFile.exists()) {
                DisplayMetrics metrics = context.getResources().getDisplayMetrics();
                int screenWidth = metrics.widthPixels;
                int screenHeight = metrics.heightPixels;
                Bitmap b = FileUtils.getBitmapScaledToDisplay(imageFile, screenHeight, screenWidth);
                if (b != null) {
                    imageView = new ImageView(getContext());
                    imageView.setPadding(2, 2, 2, 2);
                    imageView.setImageBitmap(b);
                    imageView.setId(imageId);
                    imageView.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            if (bigImageURI != null) {
                                Collect.getInstance().getActivityLogger().logInstanceAction(this, "onClick", "showImagePromptBigImage" + MediaLayout.this.selectionDesignator, MediaLayout.this.index);
                                try {
                                    File bigImage = new File(ReferenceManager.instance().DeriveReference(bigImageURI).getLocalURI());
                                    Intent i = new Intent("android.intent.action.VIEW");
                                    i.setDataAndType(Uri.fromFile(bigImage), "image/*");
                                    getContext().startActivity(i);
                                } catch (InvalidReferenceException e) {
                                    Timber.e(e, "Invalid image reference due to %s ", e.getMessage());
                                } catch (ActivityNotFoundException e) {
                                    Timber.d(e, "No Activity found to handle due to %s", e.getMessage());
                                    ToastUtils.showShortToast(getContext().getString(R.string.activity_not_found, getContext().getString(R.string.view_image)));
                                }
                            } else {
                                if (viewText instanceof RadioButton) {
                                    ((RadioButton) viewText).setChecked(true);
                                } else if (viewText instanceof CheckBox) {
                                    CheckBox checkbox = (CheckBox) viewText;
                                    checkbox.setChecked(!checkbox.isChecked());
                                }
                            }
                        }
                    });
                } else {
                    // Loading the image failed, so it's likely a bad file.
                    errorMsg = getContext().getString(R.string.file_invalid, imageFile);
                }
            } else {
                // We should have an image, but the file doesn't exist.
                errorMsg = getContext().getString(R.string.file_missing, imageFile);
            }
            if (errorMsg != null) {
                // errorMsg is only set when an error has occurred
                Timber.e(errorMsg);
                missingImage = new TextView(getContext());
                missingImage.setText(errorMsg);
                missingImage.setPadding(10, 10, 10, 10);
                missingImage.setId(imageId);
            }
        } catch (InvalidReferenceException e) {
            Timber.e(e, "Invalid image reference due to %s ", e.getMessage());
        }
    } else {
    // There's no imageURI listed, so just ignore it.
    }
    // e.g., for TextView that flag will be true
    boolean isNotAMultipleChoiceField = !RadioButton.class.isAssignableFrom(text.getClass()) && !CheckBox.class.isAssignableFrom(text.getClass());
    // Assumes LTR, TTB reading bias!
    if (viewText.getText().length() == 0 && (imageView != null || missingImage != null)) {
        // it will show a grey bar to the right of the image icon.
        if (imageView != null) {
            imageView.setScaleType(ScaleType.FIT_START);
        }
        // 
        // In this case, we have:
        // Text upper left; image upper, left edge aligned with text right edge;
        // audio upper right; video below audio on right.
        textParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        textParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        if (isNotAMultipleChoiceField) {
            imageParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
        } else {
            imageParams.addRule(RelativeLayout.RIGHT_OF, viewText.getId());
        }
        imageParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        if (audioButton != null && videoButton == null) {
            audioParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
            audioParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            audioParams.setMargins(0, 0, 11, 0);
            imageParams.addRule(RelativeLayout.LEFT_OF, audioButton.getId());
        } else if (audioButton == null && videoButton != null) {
            videoParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
            videoParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            videoParams.setMargins(0, 0, 11, 0);
            imageParams.addRule(RelativeLayout.LEFT_OF, videoButton.getId());
        } else if (audioButton != null && videoButton != null) {
            audioParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
            audioParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            audioParams.setMargins(0, 0, 11, 0);
            imageParams.addRule(RelativeLayout.LEFT_OF, audioButton.getId());
            videoParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            videoParams.addRule(RelativeLayout.BELOW, audioButton.getId());
            videoParams.setMargins(0, 20, 11, 0);
            imageParams.addRule(RelativeLayout.LEFT_OF, videoButton.getId());
        } else {
            // no need to bound it by the width of the parent...
            if (!isNotAMultipleChoiceField) {
                imageParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            }
        }
        imageParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    } else {
        // In this case, we want the image to be centered...
        if (imageView != null) {
            imageView.setScaleType(ScaleType.FIT_START);
        }
        // 
        // Text upper left; audio upper right; video below audio on right.
        // image below text, audio and video buttons; left-aligned with text.
        textParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        textParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        if (audioButton != null && videoButton == null) {
            audioParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            audioParams.setMargins(0, 0, 11, 0);
            textParams.addRule(RelativeLayout.LEFT_OF, audioButton.getId());
        } else if (audioButton == null && videoButton != null) {
            videoParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            videoParams.setMargins(0, 0, 11, 0);
            textParams.addRule(RelativeLayout.LEFT_OF, videoButton.getId());
        } else if (audioButton != null && videoButton != null) {
            audioParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            audioParams.setMargins(0, 0, 11, 0);
            textParams.addRule(RelativeLayout.LEFT_OF, audioButton.getId());
            videoParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            videoParams.setMargins(0, 20, 11, 0);
            videoParams.addRule(RelativeLayout.BELOW, audioButton.getId());
        } else {
            textParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        }
        if (imageView != null || missingImage != null) {
            imageParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
            imageParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
            if (videoButton != null) {
                imageParams.addRule(RelativeLayout.LEFT_OF, videoButton.getId());
            } else if (audioButton != null) {
                imageParams.addRule(RelativeLayout.LEFT_OF, audioButton.getId());
            }
            imageParams.addRule(RelativeLayout.BELOW, viewText.getId());
        } else {
            textParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        }
    }
    addView(viewText, textParams);
    if (audioButton != null) {
        addView(audioButton, audioParams);
    }
    if (videoButton != null) {
        addView(videoButton, videoParams);
    }
    if (imageView != null) {
        addView(imageView, imageParams);
    } else if (missingImage != null) {
        addView(missingImage, imageParams);
    }
}
Also used : Intent(android.content.Intent) AppCompatImageButton(android.support.v7.widget.AppCompatImageButton) RadioButton(android.widget.RadioButton) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) DisplayMetrics(android.util.DisplayMetrics) InvalidReferenceException(org.javarosa.core.reference.InvalidReferenceException) Bitmap(android.graphics.Bitmap) ActivityNotFoundException(android.content.ActivityNotFoundException) CheckBox(android.widget.CheckBox) RelativeLayout(android.widget.RelativeLayout) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) ImageView(android.widget.ImageView) File(java.io.File)

Aggregations

View (android.view.View)135 RecyclerView (android.support.v7.widget.RecyclerView)97 TextView (android.widget.TextView)69 Toolbar (android.support.v7.widget.Toolbar)50 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