all
This commit is contained in:
36
app/src/main/java/com/tianrun/sipcall/ui/ActivityMgr.java
Normal file
36
app/src/main/java/com/tianrun/sipcall/ui/ActivityMgr.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package com.tianrun.sipcall.ui;
|
||||
|
||||
import com.tianrun.sipcall.utils.CONS;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.ConcurrentSkipListSet;
|
||||
|
||||
public class ActivityMgr {
|
||||
public static Map<Class, TrBaseActivity> actives = new ConcurrentHashMap<>();
|
||||
public static TrBaseActivity topActivity;
|
||||
public static TrBaseActivity getActivity(Class _class){
|
||||
return actives.get(_class);
|
||||
}
|
||||
|
||||
public static void onShowActivity(TrBaseActivity a) {
|
||||
topActivity = a;
|
||||
if(!actives.containsKey(a.getClass())) {
|
||||
actives.put(a.getClass(), a);
|
||||
}
|
||||
}
|
||||
public static void onHideActivity(TrBaseActivity a) {
|
||||
actives.remove(a.getClass());
|
||||
if(a == topActivity) {
|
||||
topActivity = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendMsg(int menu, Object obj) {
|
||||
for(TrBaseActivity a : actives.values()) {
|
||||
CONS.SENDMESSAGETO( a.handler, menu, obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
67
app/src/main/java/com/tianrun/sipcall/ui/TrAdapter.java
Normal file
67
app/src/main/java/com/tianrun/sipcall/ui/TrAdapter.java
Normal file
@@ -0,0 +1,67 @@
|
||||
package com.tianrun.sipcall.ui;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.BaseAdapter;
|
||||
|
||||
import com.tianrun.sipcall.R;
|
||||
import com.tianrun.sipcall.login.MainActivity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class TrAdapter extends BaseAdapter {
|
||||
|
||||
public interface Callback {
|
||||
void initCallback(Object data, int position, View prefabView, ViewGroup parent);
|
||||
|
||||
void clickCallback(Object data, AdapterView<?> parent, View view, int position, long id);
|
||||
}
|
||||
|
||||
public List<Object> list = null;
|
||||
private Context context;
|
||||
private LayoutInflater inflater;
|
||||
private int convertViewId;
|
||||
private Callback callback;
|
||||
|
||||
public TrAdapter(Context context, int convertViewId, List<Object> list, Callback callback) {
|
||||
inflater = LayoutInflater.from(context);
|
||||
this.convertViewId = convertViewId;
|
||||
this.list = list;
|
||||
this.context = context;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
public List<Object> getList()
|
||||
{
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return list.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return list.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
if(convertView == null)
|
||||
convertView = inflater.inflate(convertViewId, null);
|
||||
callback.initCallback(getItem(position), position, convertView, parent);
|
||||
return convertView;
|
||||
}
|
||||
|
||||
}
|
||||
34
app/src/main/java/com/tianrun/sipcall/ui/TrBaseActivity.java
Normal file
34
app/src/main/java/com/tianrun/sipcall/ui/TrBaseActivity.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package com.tianrun.sipcall.ui;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
public class TrBaseActivity extends AppCompatActivity implements Handler.Callback {
|
||||
|
||||
public Handler handler = new Handler(this);
|
||||
|
||||
@Override
|
||||
public boolean handleMessage(@NonNull Message msg) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
ActivityMgr.onShowActivity(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
ActivityMgr.onHideActivity(this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
168
app/src/main/java/com/tianrun/sipcall/ui/UIUtl.java
Normal file
168
app/src/main/java/com/tianrun/sipcall/ui/UIUtl.java
Normal file
@@ -0,0 +1,168 @@
|
||||
package com.tianrun.sipcall.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.GridView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.qmuiteam.qmui.skin.QMUISkinManager;
|
||||
import com.qmuiteam.qmui.widget.dialog.QMUIBottomSheet;
|
||||
import com.qmuiteam.qmui.widget.dialog.QMUITipDialog;
|
||||
import com.tianrun.sipcall.App;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class UIUtl {
|
||||
public static void toast(String tip) {
|
||||
if (ActivityMgr.topActivity == null) return;
|
||||
try {
|
||||
ActivityMgr.topActivity.handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
QMUITipDialog tipDialog = new QMUITipDialog.Builder(ActivityMgr.topActivity)
|
||||
.setIconType(QMUITipDialog.Builder.ICON_TYPE_NOTHING)
|
||||
.setTipWord(tip)
|
||||
.create();
|
||||
tipDialog.show();
|
||||
hideToast(tipDialog);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void toastI(String tip) {
|
||||
if (ActivityMgr.topActivity == null) return;
|
||||
try {
|
||||
ActivityMgr.topActivity.handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
QMUITipDialog tipDialog = new QMUITipDialog.Builder(ActivityMgr.topActivity)
|
||||
.setIconType(QMUITipDialog.Builder.ICON_TYPE_INFO)
|
||||
.setTipWord(tip)
|
||||
.create();
|
||||
tipDialog.show();
|
||||
hideToast(tipDialog);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void toastS(String tip) {
|
||||
if (ActivityMgr.topActivity == null) return;
|
||||
try {
|
||||
ActivityMgr.topActivity.handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
QMUITipDialog tipDialog = new QMUITipDialog.Builder(ActivityMgr.topActivity)
|
||||
.setIconType(QMUITipDialog.Builder.ICON_TYPE_SUCCESS)
|
||||
.setTipWord(tip)
|
||||
.create();
|
||||
tipDialog.show();
|
||||
hideToast(tipDialog);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void toastW(String tip) {
|
||||
if (ActivityMgr.topActivity == null) return;
|
||||
try {
|
||||
ActivityMgr.topActivity.handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
QMUITipDialog tipDialog = new QMUITipDialog.Builder(ActivityMgr.topActivity)
|
||||
.setIconType(QMUITipDialog.Builder.ICON_TYPE_FAIL)
|
||||
.setTipWord(tip)
|
||||
.create();
|
||||
tipDialog.show();
|
||||
hideToast(tipDialog);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static QMUITipDialog toastLoading(String tip) {
|
||||
if (ActivityMgr.topActivity == null) return null;
|
||||
QMUITipDialog tipDialog = new QMUITipDialog.Builder(ActivityMgr.topActivity)
|
||||
.setIconType(QMUITipDialog.Builder.ICON_TYPE_LOADING)
|
||||
.setTipWord(tip)
|
||||
.create();
|
||||
tipDialog.show();
|
||||
// hideToast(tipDialog);
|
||||
return tipDialog;
|
||||
}
|
||||
|
||||
private static void hideToast(QMUITipDialog tipDialog) {
|
||||
if (ActivityMgr.topActivity == null) return;
|
||||
ActivityMgr.topActivity.handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
tipDialog.dismiss();
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
}, 1200);
|
||||
}
|
||||
|
||||
public static TrAdapter setList(Context context, GridView grid, int convertViewId, Object list, TrAdapter.Callback callback) {
|
||||
TrAdapter adapter = new TrAdapter(context, convertViewId, (List<Object>) list, callback);
|
||||
grid.setAdapter(adapter);
|
||||
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
callback.clickCallback(adapter.getItem(position), parent, view, position, id);
|
||||
}
|
||||
});
|
||||
return adapter;
|
||||
}
|
||||
|
||||
|
||||
public static void showBottomSheetList(
|
||||
CharSequence title,
|
||||
List<String> items, QMUIBottomSheet.BottomListSheetBuilder.OnSheetItemClickListener onClick) {
|
||||
showBottomSheetList(true, true, title, items, false, true, onClick);
|
||||
}
|
||||
|
||||
public static void showBottomSheetList(boolean gravityCenter,
|
||||
boolean addCancelBtn,
|
||||
CharSequence title,
|
||||
List<String> items,
|
||||
boolean allowDragDismiss,
|
||||
boolean withMark, QMUIBottomSheet.BottomListSheetBuilder.OnSheetItemClickListener onClick) {
|
||||
QMUIBottomSheet.BottomListSheetBuilder builder = new QMUIBottomSheet.BottomListSheetBuilder(App.getContext());
|
||||
builder.setGravityCenter(gravityCenter)
|
||||
.setSkinManager(QMUISkinManager.defaultInstance(App.getContext()))
|
||||
.setTitle(title)
|
||||
.setAddCancelBtn(addCancelBtn)
|
||||
.setAllowDrag(allowDragDismiss)
|
||||
.setNeedRightMark(withMark)
|
||||
.setOnSheetItemClickListener(new QMUIBottomSheet.BottomListSheetBuilder.OnSheetItemClickListener() {
|
||||
@Override
|
||||
public void onClick(QMUIBottomSheet dialog, View itemView, int position, String tag) {
|
||||
dialog.dismiss();
|
||||
// Toast.makeText(getActivity(), "Item " + (position + 1), Toast.LENGTH_SHORT).show();
|
||||
onClick.onClick(dialog, itemView, position, tag);
|
||||
}
|
||||
});
|
||||
if (withMark) {
|
||||
builder.setCheckedIndex(40);
|
||||
}
|
||||
for (int i = 1; i <= items.size(); i++) {
|
||||
builder.addItem(items.get(i));
|
||||
}
|
||||
builder.build().show();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user