欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android筆記設計范例之日記APP實現(xiàn)全流程

 更新時間:2023年01月20日 11:37:39   作者:勤奮的oyoung  
這篇文章主要介紹了Android筆記設計范例之日記APP實現(xiàn)全流程,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習吧

前言

你們好,我是oy,介紹一個簡易日記APP。

一、效果

1.啟動頁、引導頁及登陸注冊

2.日記相關功能

3.個人中心界面

二、功能介紹

1.主要功能

  • 實現(xiàn)應用啟動頁及引導頁
  • 實現(xiàn)設置密碼進入APP,對密碼進行加密處理
  • 實現(xiàn)底部導航欄,分為日記列表,新建日記,個人中心模塊
  • 實現(xiàn)對日記刪除、修改、新增的基礎功能
  • 實現(xiàn)圓形頭像,通過相冊及拍照并裁剪圖片設置頭像。可實時保存。
  • 實現(xiàn)網(wǎng)絡更新個人中心美圖。
  • 對密碼展示及關閉,跳轉應用設置界面
  • 動態(tài)獲取拍照及相冊訪問權限

2.涉及知識點

  • activity與fragment數(shù)據(jù)傳遞、頁面更新、相互跳轉。
  • SharedPrefrenced存儲、文件存儲、文件加密。
  • Android應用權限獲取及設置
  • 控件的使用:Button、EditText、AlertDialog、Imageview、ImageButton、viewPager2、
  • Toolbar、RecycleView、NavigationButton等
  • 布局的使用:LinearLayout、ConstraintLayout、RelativeLayout等
  • 調(diào)用Android系統(tǒng)應用
  • 自定義View:底部彈窗(比較復雜)、圓形頭像
  • Glide框架使用:網(wǎng)絡加載圖片
  • Android框架:MVC

三、實現(xiàn)思路

MainActivity中使用BottomNavigationView、ViewPager2、Toolbar實現(xiàn)。

public class MainActivity extends AppCompatActivity {
    private BottomNavigationView bottomNavigationView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initToolbar();
        initFragment();
        initNavigationBottom();
    }
    @SuppressLint("ResourceAsColor")
    private void initNavigationBottom() {
        bottomNavigationView = findViewById(R.id.navigation_bottom);
        bottomNavigationView.setItemIconTintList(null);
        bottomNavigationView.setOnNavigationItemSelectedListener(itemSelectedListener);
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        return super.onCreateOptionsMenu(menu);
    }
    private void initFragment() {
        DiariesFragment diariesFragment = getDiariesFragment();
        if (diariesFragment == null) {
            diariesFragment = new DiariesFragment();
            ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), diariesFragment, R.id.content);
        }
    }
    private DiariesFragment getDiariesFragment() {
        return (DiariesFragment) getSupportFragmentManager().findFragmentById(R.id.content);
    }
    private void initToolbar() {
        //設置頂部狀態(tài)欄為透明
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
    }
    private final BottomNavigationView.OnNavigationItemSelectedListener itemSelectedListener = item -> {
        switch (item.getItemId()) {
            case R.id.menu_diary:
                MeController.setToolbarVisibility(this);
                ActivityUtils.removeFragmentTOActivity(getSupportFragmentManager(), getSupportFragmentManager().findFragmentById(R.id.content));
                ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), new DiariesFragment(), R.id.content);
                break;
            case R.id.menu_me:
                findViewById(R.id.toolbar).setVisibility(View.GONE);
                ActivityUtils.removeFragmentTOActivity(getSupportFragmentManager(), getSupportFragmentManager().findFragmentById(R.id.content));
                ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), new MeFragment(), R.id.content);
                break;
            case R.id.menu_new:
                bottomNavigationView.setVisibility(View.GONE);
                MeController.setToolbarVisibility(this);
                ActivityUtils.removeFragmentTOActivity(getSupportFragmentManager(), getSupportFragmentManager().findFragmentById(R.id.content));
                ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), new AddDiaryFragment(), R.id.content);
                break;
        }
        return true;
    };
}

MainActivity的layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">
    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimary"
            android:minHeight="?attr/actionBarSize"
            android:fitsSystemWindows="true"
            android:theme="@style/Widget.AppCompat.Toolbar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
    </com.google.android.material.appbar.AppBarLayout>
    <FrameLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"/>
    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/navigation_bottom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:menu="@menu/menu_navigation"
        android:background="?android:attr/windowBackground"/>
</LinearLayout>

ViewPager2中切換不同fragment,對應導航欄新增日記、個人中心及日記列表。

public class DiariesFragment extends Fragment {
    private DiariesController mController;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mController = new DiariesController(this);
    }
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_diaries, container, false);
        mController.setDiariesList(root.findViewById(R.id.diaries_list));
        return root;
    }
    @Override
    public void onResume() {
        super.onResume();
        mController.loadDiaries();
    }
}

DiariesFragment的layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:orientation="vertical">
    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/diaries_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</RelativeLayout>
public class AddDiaryFragment extends Fragment implements View.OnClickListener {
    private AddDiaryController mController;
    private View edit_layout;
    private Button btn_confirm;
    private EditText edit_title;
    private EditText edit_desc;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mController = new AddDiaryController(this);
    }
    private void initView(View view) {
        btn_confirm = view.findViewById(R.id.add_diary_confirm);
        btn_confirm.setOnClickListener(this);
        edit_title = view.findViewById(R.id.edit_add_title);
        edit_desc = view.findViewById(R.id.edit_add_desc);
        edit_layout = view.findViewById(R.id.edit_layout);
        edit_layout.setOnClickListener(this);
    }
    @Override
    public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
        inflater.inflate(R.menu.menu_cancel, menu);
    }
    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_cancel:
                mController.closeWriteDiary(getActivity().getSupportFragmentManager(), this);
                mController.setNavigationVisibility();
                return true;
        }
        return false;
    }
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_add_diary, container, false);
        initView(root);
        return root;
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
    }
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.add_diary_confirm:
                mController.addDiaryToRepository(edit_title.getText().toString().trim(), edit_desc.getText().toString().trim());
                mController.setNavigationVisibility();
                mController.closeWriteDiary(getActivity().getSupportFragmentManager(), this);
                break;
            case R.id.edit_layout:
                mController.changeFocus(edit_desc);
                break;
        }
    }
}

AddDiaryFragment的layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_marginStart="10dp"
        android:layout_marginEnd="10dp"
        android:orientation="vertical">
        <EditText
            android:id="@+id/edit_add_title"
            android:hint="@string/add_title_hint"
            android:minLines="1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>
    <LinearLayout
        android:id="@+id/edit_layout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_marginTop="5dp"
        android:layout_marginStart="10dp"
        android:layout_marginEnd="10dp"
        android:layout_marginBottom="10dp">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingStart="5dp"
            android:paddingTop="5dp"
            android:paddingEnd="5dp"
            android:paddingBottom="5dp"
            android:background="@drawable/edit_background">
            <EditText
                android:id="@+id/edit_add_desc"
                android:hint="@string/add_title_description"
                android:gravity="top"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scrollbars="vertical"
                android:background="@null"/>
        </LinearLayout>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal">
        <Button
            android:id="@+id/add_diary_confirm"
            android:text="@string/btn_ok"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    </LinearLayout>
</LinearLayout>

將應用密碼加密保存與文件中。每次登陸獲取密碼并對比。

public class LoginDirectActivity extends AppCompatActivity implements View.OnClickListener {
    private EditText edit_input_text;
    private Button btn_comeIn;
    private TextView tv_setPsw;
    private static final String TAG = "Login2Activity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_direct_login);
        bindView();
    }
    private void bindView() {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        edit_input_text = findViewById(R.id.edit_login2_input_text);
        btn_comeIn = findViewById(R.id.btn_login2_comeIn);
        btn_comeIn.setOnClickListener(this);
        tv_setPsw = findViewById(R.id.tv_setPsw);
        tv_setPsw.setOnClickListener(this);
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_setPsw:
                Intent setPsw_intent = new Intent(LoginDirectActivity.this, LoginActivity.class);
                startActivity(setPsw_intent);
                LoginDirectActivity.this.finish();
//                overridePendingTransition(R.anim.out_to_left,R.anim.in_from_right);
                break;
            case R.id.btn_login2_comeIn:
                String psw = edit_input_text.getText().toString().trim();
                if (psw.isEmpty()) {
                    Toast.makeText(this, "密碼不能為空!", Toast.LENGTH_SHORT).show();
                    return;
                }
                String readInfoByContext = FileUtils.readInfoByContext(this);
                if (psw.equals(readInfoByContext)) {
                    Toast.makeText(this, "登錄成功!", Toast.LENGTH_SHORT).show();
                    Intent intent = new Intent(this, MainActivity.class);
                    startActivity(intent);
//                    overridePendingTransition(R.anim.out_to_left,R.anim.in_from_right);
                } else {
                    Toast.makeText(this, "密碼不正確!", Toast.LENGTH_SHORT).show();
                }
                break;
        }
    }
}

LoginDirectActivity 的layout

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".view.LoginDirectActivity">
    <Button
        android:id="@+id/btn_login2_comeIn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="40dp"
        android:layout_marginEnd="40dp"
        android:text="進入"
        app:layout_constraintBottom_toTopOf="@+id/guideline5"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />
    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="40dp"
        android:layout_marginEnd="40dp"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/guideline7">
        <ImageView
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:src="@mipmap/come_in_key" />
        <EditText
            android:id="@+id/edit_login2_input_text"
            android:hint="輸入您的密碼"
            android:inputType="textPassword"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>
    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.22" />
    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.58" />
    <TextView
        android:id="@+id/tv_login2_password_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="輸入密碼"
        android:textSize="30sp"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/guideline4" />
    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.4" />
    <TextView
        android:id="@+id/tv_setPsw"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="設置密碼"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="@+id/linearLayout"
        app:layout_constraintTop_toBottomOf="@+id/linearLayout" />
</androidx.constraintlayout.widget.ConstraintLayout>

使用SharedPrefrenced存儲日記內(nèi)容及標題。

public final class SharedPreferencesUtils {
    private static final SimpleArrayMap<String, SharedPreferencesUtils> mCaches = new SimpleArrayMap<>();
    private SharedPreferences mSharedPreferences;
    private SharedPreferencesUtils(final String spName, final int mode) {
        mSharedPreferences = YyApplication.get().getSharedPreferences(spName, mode);
    }
    public static SharedPreferencesUtils getInstance(String spName) {
        SharedPreferencesUtils utils = mCaches.get(spName);
        if (utils == null) {
            utils = new SharedPreferencesUtils(spName, Context.MODE_PRIVATE);
        }
        return utils;
    }
    public void put(final String key, final String value) {
        mSharedPreferences.edit().putString(key, value).apply();
    }
    public String get(final String key) {
        return mSharedPreferences.getString(key, "");
    }
    public void remove(final String key) {
        mSharedPreferences.edit().remove(key).apply();
    }
}

總結

以上就是今天講的內(nèi)容,本文僅僅簡單介紹了Android日記APP,需要掌握上述知識點,能夠較好的理解此應用邏輯。

到此這篇關于Android筆記設計范例之日記APP實現(xiàn)全流程的文章就介紹到這了,更多相關Android日記APP內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • Android連接指定Wifi的方法實例代碼

    Android連接指定Wifi的方法實例代碼

    本篇文章主要記錄一下Android中打開Wifi、獲取Wifi接入點信息及連接指定接入點的方法,通過小編自己寫的demo主要用于測試接口的基本功能,具體實例代碼大家通過本文一起學習吧
    2017-03-03
  • Android編程獲取地理位置的經(jīng)度和緯度實例

    Android編程獲取地理位置的經(jīng)度和緯度實例

    這篇文章主要介紹了Android編程獲取地理位置的經(jīng)度和緯度實現(xiàn)方法,結合實例形式詳細分析了Android操作系統(tǒng)服務調(diào)用GPS實現(xiàn)定位的相關技巧,需要的朋友可以參考下
    2016-01-01
  • 淺析Android手機衛(wèi)士之抖動輸入框和手機震動

    淺析Android手機衛(wèi)士之抖動輸入框和手機震動

    這篇文章主要介紹了淺析Android手機衛(wèi)士之輸入框抖動和手機震動的相關資料,需要的朋友可以參考下
    2016-04-04
  • Android framework ATMS啟動流程

    Android framework ATMS啟動流程

    這篇文章主要為大家介紹了Android framework ATMS啟動流程示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-03-03
  • Android 判斷網(wǎng)絡狀態(tài)對音頻靜音的實現(xiàn)方法

    Android 判斷網(wǎng)絡狀態(tài)對音頻靜音的實現(xiàn)方法

    最近小編做項目遇到這樣的需求,需要根據(jù)當前場景讓app變的智能,讓app根據(jù)使用者當前網(wǎng)絡狀態(tài),自動記性靜音等操作,具體怎么實現(xiàn)呢?下面小編給大家分享實例代碼,需要的朋友參考下吧
    2018-10-10
  • Android手勢密碼view學習筆記(一)

    Android手勢密碼view學習筆記(一)

    這篇文章主要為大家詳細介紹了Android手勢密碼view的學習筆記,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • Android 解決WebView調(diào)用loadData()方法顯示亂碼的問題

    Android 解決WebView調(diào)用loadData()方法顯示亂碼的問題

    這篇文章主要介紹了Android 解決WebView調(diào)用loadData()方法顯示亂碼的問題的相關資料,希望通過本文能幫助到大家解決這樣的問題,需要的朋友可以參考下
    2017-09-09
  • 詳解Android的四大應用程序組件

    詳解Android的四大應用程序組件

    這篇文章主要介紹了Android的應用程序組件的相關資料,幫助大家更好的理解和使用Android,感興趣的朋友可以了解下
    2021-01-01
  • Android中button點擊后字體的變色效果

    Android中button點擊后字體的變色效果

    button的點擊效果無疑是非常簡單的,接下來通過本文給大家介紹下如何添加button點擊的字體顏色變化效果,感興趣的朋友一起看看吧
    2016-10-10
  • Android ProgressDialog使用總結

    Android ProgressDialog使用總結

    ProgressDialog 繼承自AlertDialog,AlertDialog繼承自Dialog,實現(xiàn)DialogInterface接口,本文給大家介紹Android ProgressDialog使用總結的相關知識,需要的朋友通過此文一起學習吧
    2016-01-01

最新評論