Android的风格通话记录通话记录、风格、Android

2023-09-04 23:05:42 作者:忆初♡

我要创建类似于Android的呼叫日志中的活动。我还没有找到关于它的很多信息。我发现是这样的例子,有一个主要活动,其中有3个按钮:

I have to create a activity similar to the android's call log. I haven't found much info about it. what I found is this example, that has a main activity where there are 3 buttons:

1拨出电话列表 2 - 内迁通话清单 3未接来电列表

1- Outgoing call list 2- Ingoing call list 3- Missed call list

和每个按钮发送到另一个活动至极与每个呼叫的详细信息列表视图。

And each button sends to another activity wich is a listview with the details of each call.

不过,我需要的,是首先要统一所有这个应用程序到一个只有布局,至极显示所有错过,outoging和迁入的时间来电,按日期列出。我现在认为这应该是简单的,但我没有得到能够做到这一点,这是因为我请你帮忙。接下来的事情,我应该在这之后做的,是修改列表视图布局,以显示通话记录作为机器人展示它,与手机的图标和选项打电话给那个人,如果你摸的名字。

But what I need, is first to unify all this app into one only layout, wich shows all missed, outoging and ingoing calls at a time, listed by date. I now that this should be simple, but I'm not getting able to do it, this is because I ask you for help. The next thing that i should do after this, is to modify the listview layout to show the call log as android shows it, with the phone icons and the option to call that person if you touch the name.

但首先,我需要在运行我需要的方式应用程序。

But first of all, I need the app running the way I need it.

这是在code为主要布局,其中有3个按钮:

This is the code for the main layout where there are the 3 buttons:

public class CallLogsDemoActivity extends Activity {

public static ArrayList<CallLogModel> outgoingList;
public static ArrayList<CallLogModel> incomingList;
public static ArrayList<CallLogModel> missedcallList;

public static final int OUTGOING_CALLS = 1;
public static final int INCOMING_CALLS = 2;
public static final int MISSED_CALLS = 3;

public static final String CALL_TYPE = "TYPE";

private Button inBtn, outBtn, missedBtn;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);
    outBtn = (Button) findViewById(R.id.button1);
    inBtn = (Button) findViewById(R.id.button2);
    missedBtn = (Button) findViewById(R.id.button3);

    inBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            showIncomingList();
        }
    });
    outBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            showOutGoingList();
        }
    });
    missedBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            showMissedList();
        }
    });
    outgoingList = new ArrayList<CallLogModel>();
    incomingList = new ArrayList<CallLogModel>();
    missedcallList = new ArrayList<CallLogModel>();

    new ReadLogs().execute();
}

private void showIncomingList() {
    Intent intent = new Intent(this, CallLogs.class);
    intent.putExtra(CALL_TYPE, INCOMING_CALLS);
    startActivity(intent);
}

private void showMissedList() {
    Intent intent = new Intent(this, CallLogs.class);
    intent.putExtra(CALL_TYPE, MISSED_CALLS);
    startActivity(intent);
}

private void showOutGoingList() {
    Intent intent = new Intent(this, CallLogs.class);
    intent.putExtra(CALL_TYPE, OUTGOING_CALLS);
    startActivity(intent);
}

private String getDuration(long milliseconds) {
    int seconds = (int) (milliseconds / 1000) % 60;
    int minutes = (int) ((milliseconds / (1000 * 60)) % 60);
    int hours = (int) ((milliseconds / (1000 * 60 * 60)) % 24);
    if (hours < 1)
        return minutes + ":" + seconds;
    return hours + ":" + minutes + ":" + seconds;
}

private String getDateTime(long milliseconds) {
    Date date = new Date(milliseconds);
    //return DateFormat.getDateTimeInstance().format(new Date());

    return date.toLocaleString();
}

private void readCallLogs() {

    missedcallList.clear();
    incomingList.clear();
    outgoingList.clear();

    Cursor callLogCursor = getContentResolver().query(
            android.provider.CallLog.Calls.CONTENT_URI, null, null, null,
            android.provider.CallLog.Calls.DEFAULT_SORT_ORDER);
    if (callLogCursor != null) {
        while (callLogCursor.moveToNext()) {
            String id = callLogCursor.getString(callLogCursor
                    .getColumnIndex(CallLog.Calls._ID));
            String name = callLogCursor.getString(callLogCursor
                    .getColumnIndex(CallLog.Calls.CACHED_NAME));
            String cacheNumber = callLogCursor.getString(callLogCursor
                    .getColumnIndex(CallLog.Calls.CACHED_NUMBER_LABEL));
            String number = callLogCursor.getString(callLogCursor
                    .getColumnIndex(CallLog.Calls.NUMBER));
            long dateTimeMillis = callLogCursor.getLong(callLogCursor
                    .getColumnIndex(CallLog.Calls.DATE));
            long durationMillis = callLogCursor.getLong(callLogCursor
                    .getColumnIndex(CallLog.Calls.DURATION));
            int callType = callLogCursor.getInt(callLogCursor
                    .getColumnIndex(CallLog.Calls.TYPE));

            String duration = getDuration(durationMillis * 1000);

            String dateString = getDateTime(dateTimeMillis);

            if (cacheNumber == null)
                cacheNumber = number;
            if (name == null)
                name = "No Name";

            CallLogModel callLogModel = new CallLogModel(name, cacheNumber,
                    duration, dateString);
            if (callType == CallLog.Calls.OUTGOING_TYPE) {
                outgoingList.add(callLogModel);

            } else if (callType == CallLog.Calls.INCOMING_TYPE) {
                incomingList.add(callLogModel);

            } else if (callType == CallLog.Calls.MISSED_TYPE) {
                missedcallList.add(callLogModel);

            }

        }
        callLogCursor.close();
    }
}

private class ReadLogs extends AsyncTask<Void, Void, Void> {

    /* Object */
    ProgressDialog dialog;

    /*
     * Function name: onPreExecute Parameters: Void params Return: void
     */
    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();
        dialog = ProgressDialog.show(CallLogsDemoActivity.this,
                "Reading Call Logs...", "Please wait...", true);
    }

    /*
     * Function name: doInBackground Parameters: Void params Return: void
     */
    @Override
    protected Void doInBackground(Void... params) {
        // TODO Auto-generated method stub
        readCallLogs();
        return null;
    }

    /*
     * Function name: onPostExecute Parameters: Void result Return: void
     */
    @Override
    protected void onPostExecute(Void result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
        dialog.dismiss();
    }
}

}

这是其他活动至极显示列表:

And this is the other activity wich shows the list:

public class CallLogs extends Activity {
private ListView mainListView;
private ArrayAdapter<CallLogModel> listAdapter;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.listview);
    mainListView = (ListView) findViewById(R.id.listView);
    mainListView.setSmoothScrollbarEnabled(true);

    Bundle extras = getIntent().getExtras();
    int callType = extras.getInt(CallLogsDemoActivity.CALL_TYPE);
    if (callType == CallLogsDemoActivity.OUTGOING_CALLS)
        listAdapter = new CallLogsArrayAdapter(this,
                CallLogsDemoActivity.outgoingList);
    else if (callType == CallLogsDemoActivity.INCOMING_CALLS)
        listAdapter = new CallLogsArrayAdapter(this,
                CallLogsDemoActivity.incomingList);
    else if (callType == CallLogsDemoActivity.MISSED_CALLS)
        listAdapter = new CallLogsArrayAdapter(this,
                CallLogsDemoActivity.missedcallList);
    mainListView.setAdapter(listAdapter);

}

public void initElements() {
    listAdapter.notifyDataSetChanged();
}

}

至于说,我trye​​d统一这个code,显示在一个唯一的布局和显示所有的呼叫tipes在为机器人做它一个时间,但不实现它。

As said, I tryed to unify this code to show in one only layout and show all call tipes at a time as android does it, but dont achieve it.

推荐答案

更​​改此code

int callType = extras.getInt(CallLogsDemoActivity.CALL_TYPE);
if (callType == CallLogsDemoActivity.OUTGOING_CALLS)
    listAdapter = new CallLogsArrayAdapter(this,
            CallLogsDemoActivity.outgoingList);
else if (callType == CallLogsDemoActivity.INCOMING_CALLS)
    listAdapter = new CallLogsArrayAdapter(this,
            CallLogsDemoActivity.incomingList);
else if (callType == CallLogsDemoActivity.MISSED_CALLS)
    listAdapter = new CallLogsArrayAdapter(this,
            CallLogsDemoActivity.missedcallList);
mainListView.setAdapter(listAdapter);

要这个

        int callType = extras.getInt(CallLogsDemoActivity.CALL_TYPE);
    ArrayList<CallLogModel> collectiveList = new ArrayList<CallLogModel>();
    collectiveList.addAll(CallLogsDemoActivity.outgoingList);
    collectiveList.addAll(CallLogsDemoActivity.incomingList);
    collectiveList.addAll(CallLogsDemoActivity.missedcallList);
    listAdapter = new CallLogsArrayAdapter(this,collectiveList);
    mainListView.setAdapter(listAdapter);