Last active
November 6, 2017 11:48
-
-
Save alfianyusufabdullah/c2f86a4e673ad32594a8d31d83d8353d to your computer and use it in GitHub Desktop.
Simple Broadcast Android.. Simple Jangan Baper #JanganLupaBahagia
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package jonesrandom.tesbroadcast; | |
| import android.content.Intent; | |
| import android.support.v4.content.LocalBroadcastManager; | |
| import android.support.v7.app.AppCompatActivity; | |
| import android.os.Bundle; | |
| import android.view.View; | |
| import android.widget.Button; | |
| import android.widget.EditText; | |
| public class MainActivity extends AppCompatActivity { | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| final EditText etMessage = findViewById(R.id.text); | |
| Button btn = findViewById(R.id.settext); | |
| btn.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View view) { | |
| Intent i = new Intent(MyTextView.ACTION_TEXT); | |
| i.putExtra(MyTextView.ACTION_KEY, etMessage.getText().toString()); | |
| LocalBroadcastManager.getInstance(MainActivity.this).sendBroadcast(i); | |
| } | |
| }); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package jonesrandom.tesbroadcast; | |
| import android.annotation.SuppressLint; | |
| import android.content.BroadcastReceiver; | |
| import android.content.Context; | |
| import android.content.Intent; | |
| import android.content.IntentFilter; | |
| import android.support.v4.content.LocalBroadcastManager; | |
| import android.util.AttributeSet; | |
| import android.widget.TextView; | |
| /** | |
| * Created by jonesrandom on 11/6/17. | |
| * | |
| * #JanganLupaBahagia | |
| */ | |
| @SuppressLint("AppCompatCustomView") | |
| public class MyTextView extends TextView { | |
| public static String ACTION_TEXT = "#JanganLupaBahagia"; | |
| public static String ACTION_KEY = "#JombloGarisKeras"; | |
| public MyTextView(Context context) { | |
| super(context); | |
| ///TODO - Biarin Kosong Ato Terserah Mau Isi Apa Terserah ente | |
| } | |
| public MyTextView(Context context, AttributeSet attrs) { | |
| super(context, attrs); | |
| LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context); | |
| lbm.registerReceiver(new BroadcastReceiver() { | |
| @Override | |
| public void onReceive(Context context, Intent intent) { | |
| String text = intent.getStringExtra(ACTION_KEY); | |
| setText(text); | |
| /* Kalo ImageView Yang Dikirim Path Lokasi Gambar | |
| * | |
| * String Path = intent.getStringExtra("KEY"); | |
| * Bitmap bmp = BitmapFactory.decodeFile(Path); | |
| * setImageBitmap(bmp); | |
| * | |
| * */ | |
| ///TODO - simpan ke sharepreferencesnya dimari | |
| } | |
| }, new IntentFilter(ACTION_TEXT)); | |
| } | |
| public MyTextView(Context context, AttributeSet attrs, int defStyleAttr) { | |
| super(context, attrs, defStyleAttr); | |
| ///TODO - Biarin Kosong Ato Terserah Mau Isi Apa Terserah ente | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment