• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.example.android.directshare;
18 
19 import android.app.Activity;
20 import android.content.Intent;
21 import android.os.Bundle;
22 import android.view.View;
23 import android.widget.EditText;
24 import android.widget.Toolbar;
25 
26 /**
27  * Provides the landing screen of this sample. There is nothing particularly interesting here. All
28  * the codes related to the Direct Share feature are in {@link SampleChooserTargetService}.
29  */
30 public class MainActivity extends Activity {
31 
32     private EditText mEditBody;
33 
34     @Override
onCreate(Bundle savedInstanceState)35     protected void onCreate(Bundle savedInstanceState) {
36         super.onCreate(savedInstanceState);
37         setContentView(R.layout.main);
38         setActionBar((Toolbar) findViewById(R.id.toolbar));
39         mEditBody = (EditText) findViewById(R.id.body);
40         findViewById(R.id.share).setOnClickListener(mOnClickListener);
41     }
42 
43     private View.OnClickListener mOnClickListener = new View.OnClickListener() {
44         @Override
45         public void onClick(View v) {
46             switch (v.getId()) {
47                 case R.id.share:
48                     share();
49                     break;
50             }
51         }
52     };
53 
54     /**
55      * Emits a sample share {@link Intent}.
56      */
share()57     private void share() {
58         Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
59         sharingIntent.setType("text/plain");
60         sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, mEditBody.getText().toString());
61         startActivity(Intent.createChooser(sharingIntent, getString(R.string.send_intent_title)));
62     }
63 
64 }
65