UniversalImageView Android - PullRequest
       25

UniversalImageView Android

0 голосов
/ 11 октября 2018
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.NavigationView;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.tdevelopmentstudio.shotit.Home.Home;
import com.tdevelopmentstudio.shotit.NavMenus.Options;
import com.tdevelopmentstudio.shotit.NavMenus.ProfileSettings;
import com.tdevelopmentstudio.shotit.NavMenus.SignOut;
import com.tdevelopmentstudio.shotit.R;
import com.tdevelopmentstudio.shotit.Utils.BottomNavigationViewHelper_Home;
import com.tdevelopmentstudio.shotit.Utils.GridImageAdapter;
import com.tdevelopmentstudio.shotit.Utils.SquareImageView;
import com.tdevelopmentstudio.shotit.Utils.UniversalImageLoader;

import java.util.ArrayList;


public class ProfileActivity extends AppCompatActivity {

    private SquareImageView profilePhoto;
    private NavigationView navigationView;
    private DrawerLayout activity_profile_drawer_Lout;
    private  ProgressBar mProgressBar;
    ActionBarDrawerToggle actionBarDrawerToggle;
    Toolbar toolbar;

    //to highlight the bottom nav bar buttons when it is selected
    private static final int ACTIVITY_NUM = 4;
    // gridView profile pics column numbers
    private static final int NUM_GRID_COLUMNS = 2;
    private Context mContext = ProfileActivity.this;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_profile);
        setupBottomNavigationView();
        tempGridSetup();
        setupActivityWidgets();
        setProfileImage();



        // for the swipe menu
        setSupportActionBar(toolbar);
        activity_profile_drawer_Lout = findViewById(R.id.activity_profile_drawer_Lout);
        navigationView = findViewById(R.id.navigationView);
        actionBarDrawerToggle = new ActionBarDrawerToggle(this, activity_profile_drawer_Lout,
                toolbar, R.string.Open, R.string.Close);
        activity_profile_drawer_Lout.setDrawerListener(actionBarDrawerToggle);

        navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {

                int id = menuItem.getItemId();

                switch (id)

                {
                    case R.id.home_ic:
                        Intent intent = new Intent(getApplicationContext(), Home.class);
                        startActivity(intent);
                        menuItem.setChecked(true);
                        displayMessage("going to home...");
                        activity_profile_drawer_Lout.closeDrawers();
                        return true;

                    case R.id.profile_settings_ic:
                        Intent intent1 = new Intent(getApplicationContext(), ProfileSettings.class);
                        startActivity(intent1);
                        menuItem.setChecked(true);
                        displayMessage("going to profile settings...");
                        activity_profile_drawer_Lout.closeDrawers();
                        return true;

                    case R.id.options_ic:
                        Intent intent2 = new Intent(getApplicationContext(), Options.class);
                        startActivity(intent2);
                        menuItem.setChecked(true);
                        displayMessage("going to options...");
                        activity_profile_drawer_Lout.closeDrawers();
                        return true;

                    case R.id.signOut_ic:
                        Intent intent3 = new Intent(getApplicationContext(), SignOut.class);
                        startActivity(intent3);
                        menuItem.setChecked(true);
                        displayMessage("signing out...");
                        activity_profile_drawer_Lout.closeDrawers();
                        return true;


                }

                return false;
            }
        });

    }
    private void setProfileImage(){
        String imgURL = "https://cdn.armut.com/UserPics/tr:w-325,h-325/fbfbdfc1-7f09-4c77-babb-a03278fb1b4c.jpg";
        UniversalImageLoader.setImage(imgURL,profilePhoto,mProgressBar,"");

    }
    private void setupActivityWidgets(){
        mProgressBar = findViewById(R.id.profilepic_progressbar);
        mProgressBar.setVisibility(View.GONE);
        profilePhoto = findViewById(R.id.profilePic_ImgView);


    }

    private void tempGridSetup(){
        ArrayList<String> imgURLs = new ArrayList<>();
        imgURLs.add("https://cdn.armut.com/UserPics/tr:w-325,h-325/fbfbdfc1-7f09-4c77-babb-a03278fb1b4c.jpg");
        setupImageGrid(imgURLs);
    }
    private void setupImageGrid(ArrayList<String> imgURLs){
        GridView gridView = findViewById(R.id.gridView_profile_pics);
        int gridWidth = getResources().getDisplayMetrics().widthPixels;
        int imageWidth = gridWidth/NUM_GRID_COLUMNS;
        gridView.setColumnWidth(imageWidth);
        GridImageAdapter adapter = new GridImageAdapter(mContext, R.layout.layout_grid_imageview, "", imgURLs);
        gridView.setAdapter(adapter);
    }

    private void displayMessage(String message) {
        Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
    }


    //setups for bottom navigation view
    private void setupBottomNavigationView(){

        BottomNavigationViewEx bottomNavigationViewEx = findViewById(R.id.bottom_nav_view_home);
        BottomNavigationViewHelper_Home.setupBottomNavigationView(bottomNavigationViewEx);
        BottomNavigationViewHelper_Home.enableNavigation(mContext, bottomNavigationViewEx);
        //to highlight the bottom nav bar buttons when it is selected
        Menu menu = bottomNavigationViewEx.getMenu();
        MenuItem menuItem = menu.getItem(ACTIVITY_NUM);
        menuItem.setChecked(true);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.profile_account_settings, menu);
        return true;

    }
    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);

        actionBarDrawerToggle.syncState();
    }

    }
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:id="@+id/activity_profile_drawer_Lout">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <include layout="@layout/layout_center_profile"/>

        <include layout="@layout/layout_home_bottom_nav_view"/>

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/content_frame"/>
    </RelativeLayout>


    <android.support.design.widget.NavigationView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/navigationView"
        android:layout_gravity = "start"
        app:menu="@menu/profile_account_settings"
        />

</android.support.v4.widget.DrawerLayout>

// Мне знаком этот профиль с Instagram.Тем не менее, когда я пытался кодировать UniversalImageView и GridView, у меня нет ошибок во время работы, но происходит сбой виртуального устройства при выполнении этого действия.Я понятия не имею, в чем проблема, потому что андроид студия не показывает мне никакой ошибки на странице кодирования.Благодарим за любую помощь!

открытый класс ProfileActivity расширяет AppCompatActivity {

private SquareImageView profilePhoto;
private NavigationView navigationView;
private DrawerLayout activity_profile_drawer_Lout;
private  ProgressBar mProgressBar;
ActionBarDrawerToggle actionBarDrawerToggle;
Toolbar toolbar;

//to highlight the bottom nav bar buttons when it is selected
private static final int ACTIVITY_NUM = 4;
// gridView profile pics column numbers
private static final int NUM_GRID_COLUMNS = 2;
private Context mContext = ProfileActivity.this;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profile);
    setupBottomNavigationView();
    tempGridSetup();
    setupActivityWidgets();
    setProfileImage();



    // for the swipe menu
    setSupportActionBar(toolbar);
    activity_profile_drawer_Lout = findViewById(R.id.activity_profile_drawer_Lout);
    navigationView = findViewById(R.id.navigationView);
    actionBarDrawerToggle = new ActionBarDrawerToggle(this, activity_profile_drawer_Lout,
            toolbar, R.string.Open, R.string.Close);
    activity_profile_drawer_Lout.setDrawerListener(actionBarDrawerToggle);

    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {

            int id = menuItem.getItemId();

            switch (id)

            {
                case R.id.home_ic:
                    Intent intent = new Intent(getApplicationContext(), Home.class);
                    startActivity(intent);
                    menuItem.setChecked(true);
                    displayMessage("going to home...");
                    activity_profile_drawer_Lout.closeDrawers();
                    return true;

                case R.id.profile_settings_ic:
                    Intent intent1 = new Intent(getApplicationContext(), ProfileSettings.class);
                    startActivity(intent1);
                    menuItem.setChecked(true);
                    displayMessage("going to profile settings...");
                    activity_profile_drawer_Lout.closeDrawers();
                    return true;

                case R.id.options_ic:
                    Intent intent2 = new Intent(getApplicationContext(), Options.class);
                    startActivity(intent2);
                    menuItem.setChecked(true);
                    displayMessage("going to options...");
                    activity_profile_drawer_Lout.closeDrawers();
                    return true;

                case R.id.signOut_ic:
                    Intent intent3 = new Intent(getApplicationContext(), SignOut.class);
                    startActivity(intent3);
                    menuItem.setChecked(true);
                    displayMessage("signing out...");
                    activity_profile_drawer_Lout.closeDrawers();
                    return true;


            }

            return false;
        }
    });

}
private void setProfileImage(){
    String imgURL = "https://cdn.armut.com/UserPics/tr:w-325,h-325/fbfbdfc1-7f09-4c77-babb-a03278fb1b4c.jpg";
    UniversalImageLoader.setImage(imgURL,profilePhoto,mProgressBar,"");

}
private void setupActivityWidgets(){
    mProgressBar = findViewById(R.id.profilepic_progressbar);
    mProgressBar.setVisibility(View.GONE);
    profilePhoto = findViewById(R.id.profilePic_ImgView);


}

private void tempGridSetup(){
    ArrayList<String> imgURLs = new ArrayList<>();
    imgURLs.add("https://cdn.armut.com/UserPics/tr:w-325,h-325/fbfbdfc1-7f09-4c77-babb-a03278fb1b4c.jpg");
    setupImageGrid(imgURLs);
}
private void setupImageGrid(ArrayList<String> imgURLs){
    GridView gridView = findViewById(R.id.gridView_profile_pics);
    int gridWidth = getResources().getDisplayMetrics().widthPixels;
    int imageWidth = gridWidth/NUM_GRID_COLUMNS;
    gridView.setColumnWidth(imageWidth);
    GridImageAdapter adapter = new GridImageAdapter(mContext, R.layout.layout_grid_imageview, "", imgURLs);
    gridView.setAdapter(adapter);
}

private void displayMessage(String message) {
    Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}


//setups for bottom navigation view
private void setupBottomNavigationView(){

    BottomNavigationViewEx bottomNavigationViewEx = findViewById(R.id.bottom_nav_view_home);
    BottomNavigationViewHelper_Home.setupBottomNavigationView(bottomNavigationViewEx);
    BottomNavigationViewHelper_Home.enableNavigation(mContext, bottomNavigationViewEx);
    //to highlight the bottom nav bar buttons when it is selected
    Menu menu = bottomNavigationViewEx.getMenu();
    MenuItem menuItem = menu.getItem(ACTIVITY_NUM);
    menuItem.setChecked(true);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.profile_account_settings, menu);
    return true;

}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);

    actionBarDrawerToggle.syncState();
}

}
...