快過年了,來分享一個個人制作的節日祝福軟件
個人想著過年了,要發祝福短信之類的,於是想著想著,就自己動手隨便弄了一個小小的祝福軟件,功能很簡單,供大家開心發祝福使用,謝謝。
2019節日祝福多多,上千條祝福短信,精美的節日賀卡,節日分為農歷節日和公歷節日,可以通過短信微信等第三方應用發送節日祝福給家人和朋友,還可以通過分享功能分享到其他途徑傳播祝福信息。
【1】收集大量公歷農歷節日。
【2】支持復制分享。
【3】可作為節日祝福發送給朋友們。
【4】無註冊和登錄功能
【5】日常祝福實用小工具方便快捷使用
【6】專門提供給用戶送家人和朋友節日祝福,送去溫馨的問候
現在說一下該軟件主要做法,做法很簡單:
1】祝福內容數據,網上自己收集整理成json格式數據
3】讀取assets裏面文件並轉成String數據
public static String readData(Context context, String fileName) {
InputStream inStream = null;
String data = null;
try {
inStream = context.getAssets().open(fileName); //打開assets目錄中的文本文件
byte[] bytes = new byte[inStream.available()]; //inStream.available()為文件中的總byte數
inStream.close();
data = new String(bytes, "utf-8"); //將bytes轉為utf-8字符串
} catch (IOException e) {
Log.e("AssetsHelper",e.toString());
e.printStackTrace();
}
return data;
}
4】然後用gson解析它生成對應Bean類 String newyears = AssetsHelper.readData(getContext(), "newyears"); TestBean testBean = GsonUtil.buildGson().fromJson(newyears, TestBean.class); 5】最後獲取TestBean類對應容器List數據設置到RecyclerView控件裏對應的item
布局layout上面進行展示
int pos = getArguments().getInt(POS);
RecyclerView mRecyler = (RecyclerView) view.findViewById(R.id.recycle_view);
LinearLayoutManager manager = new LinearLayoutManager(getContext());
manager.setOrientation(LinearLayout.VERTICAL);
mRecyler.setLayoutManager(manager);
mRecyler.setAdapter(new MyTAdapter(pos));
class MyTAdapter extends RecyclerView.Adapter<MyHolder>{
private int pos;
public MyTAdapter(int pos)
{
this.pos = pos;
}
@Override
public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(getContext()).inflate(R.layout.item_test, parent, false);
MyHolder mVH = new MyHolder(view);
return mVH;
}
@Override
public void onBindViewHolder(MyHolder holder, int position) {
String mtitle="空";
switch (pos)
{
case 0:
mtitle=testBean.getYears().get(position).getTitle();
break;
case 1:
mtitle=testBean.getQrj().get(position).getTitle();
break;
case 2:
mtitle=testBean.getYjj().get(position).getTitle();
break;
case 3:
mtitle=testBean.getSr().get(position).getTitle();
break;
case 4:
mtitle=testBean.getJh().get(position).getTitle();
break;
case 5:
mtitle=testBean.getSdj().get(position).getTitle();
break;
case 6:
mtitle=testBean.getLdj().get(position).getTitle();
break;
case 7:
mtitle=testBean.getMqj().get(position).getTitle();
break;
case 8:
mtitle=testBean.getFqj().get(position).getTitle();
break;
case 9:
mtitle=testBean.getDwj().get(position).getTitle();
break;
case 10:
mtitle=testBean.getZqj().get(position).getTitle();
break;
}
holder.tvid.setText("第"+(position+1)+"條祝福語:");
holder.tv_1.setText(mtitle);
final String finalMtitle = mtitle;
holder.share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
shareMsg(getContext(),"分享好友","分享祝福", finalMtitle);
}
});
holder.copy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
copy(finalMtitle);
}
});
}
@Override
public int getItemCount() {
int p=0;
switch (pos)
{
case 0:
p=testBean.getYears().size();
break;
case 1:
p=testBean.getQrj().size();
break;
case 2:
p=testBean.getYjj().size();
break;
case 3:
p=testBean.getSr().size();
break;
case 4:
p=testBean.getJh().size();
break;
case 5:
p=testBean.getSdj().size();
break;
case 6:
p=testBean.getLdj().size();
break;
case 7:
p=testBean.getMqj().size();
break;
case 8:
p=testBean.getFqj().size();
break;
case 9:
p=testBean.getDwj().size();
break;
case 10:
p=testBean.getZqj().size();
break;
}
return p;
}
}
6】分享功能時是調用系統分享來實現的:
public static void shareMsg(Context context, String activityTitle, String msgTitle, String msgText) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain"); // 純文本
intent.putExtra(Intent.EXTRA_SUBJECT, msgTitle);
intent.putExtra(Intent.EXTRA_TEXT, msgText);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(Intent.createChooser(intent, activityTitle));
}
7】文本復制功能調用android系統鍵盤管理ClipboardManager復制功能:
public void copy(String stext)
{
ClipboardManager cm = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData mClipData = ClipData.newPlainText("Label", stext);
cm.setPrimaryClip(mClipData);
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle("本條祝福語已復制成功").setNegativeButton("確定",null).show();
//ToastUtil.toastShow(getContext(), "內容已復制到剪切板");
}
8】賀卡圖片保存到android手機本地裏,圖庫相冊可以查看該圖片,需要打開系統讀寫權限:
<!-- #寫入外部存儲 android.permission.WRITE_EXTERNAL_STORAGE,允許程序寫入外部存儲,如SD卡上寫文件 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- #可以讀取設備外部存儲空間(內置SDcard和外置SDCard)的文件 -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), imgrid);
boolean b = SavePicUtils.saveImageToGallery(this , bitmap);
if (b)
{
Toast.makeText(this, "已成功保存到相冊裏", Toast.LENGTH_SHORT).show();
}else
{
Toast.makeText(this, "保存失敗!!", Toast.LENGTH_SHORT).show();
}
//保存文件到指定路徑
public static boolean saveImageToGallery(Context context, Bitmap bmp) {
// 首先保存圖片
String storePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "zhufudaquan";
File appDir = new File(storePath);
if (!appDir.exists()) {
appDir.mkdir();
}
String fileName = System.currentTimeMillis() + ".jpg";
File file = new File(appDir, fileName);
try {
FileOutputStream fos = new FileOutputStream(file);
//通過io流的方式來壓縮保存圖片
boolean isSuccess = bmp.compress(Bitmap.CompressFormat.JPEG, 60, fos);
fos.flush();
fos.close();
//把文件插入到系統圖庫
MediaStore.Images.Media.insertImage(context.getContentResolver(), file.getAbsolutePath(), fileName, null);
//保存圖片後發送廣播通知更新數據庫
Uri uri = Uri.fromFile(file);
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri));
if (isSuccess) {
return true;
} else {
return false;
}
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
快過年了,來分享一個個人制作的節日祝福軟件