ImgR - Visualization
📊 Overview
ImgR is a powerful, lightweight, and flexible visualization extension designed to transform raw information into clear, compelling, and interactive visual experiences. Built for professionals, students, analysts, researchers, and developers, ImgR enables users to quickly convert complex inputs into visually structured, easy-to-understand representations.
At its core, ImgR simplifies visual communication of information. Instead of static tables or unstructured text, ImgR empowers users to generate insightful, interactive visuals that highlight trends, relationships, and patterns. Optimized for performance, ImgR ensures smooth responsiveness even when handling large-scale datasets or frequently updated content.
With its user-friendly interface and advanced customization features, ImgR bridges the gap between technical functionality and visual storytelling. Whether you are presenting a concept, analyzing performance, or organizing information visually, ImgR adapts seamlessly to your workflow and enhances productivity.
✨ Key Features
📈 Visualization Types
- Line charts
- Bar charts (stacked, grouped, horizontal)
- Pie and donut charts
- Scatter plots
- Heatmaps
- Flowcharts and network diagrams
- Tree maps and hierarchical charts
- Timeline visualizations
🖱️ Interactive Elements
- Hover-based tooltips
- Zoom and pan capabilities
- Dynamic filtering and segmentation
- Drill-down functionality for detailed exploration
- Click-to-highlight and selection modes
- Real-time data refresh
🎨 Appearance Customization
- Theme presets: light, dark, minimal, high contrast
- Adjustable fonts, spacing, and layout
- Custom color palettes and gradients
- Grid and alignment controls
- Responsive design for desktop, tablet, and large screens
- Real-time refresh and auto-update
- Drag-and-drop interface for easy configuration
- Supports structured (CSV, JSON, SQL) and semi-structured data
- Export options: PNG, JPG, PDF, SVG, and shareable links
- API access for developers
- Optimized rendering engine for large datasets
🔧 Installation
ImgR can be installed directly from your platform’s official extension or plugin marketplace.
- Search for “ImgR”
- Click Install
- Grant required permissions
- Activate the extension within your workspace or application
Basic usage is enabled immediately after installation. Advanced features can be configured through the dedicated settings panel.
🚀 Getting Started
Once installed, open ImgR from the extension panel or toolbar. Follow these steps:
- Connect your data source (CSV, JSON, database, or API)
- Choose a visualization type from the gallery
- Adjust layout and parameters (colors, labels, axes, filters)
- Preview in real time with interactive controls
- Save, export, or share your final result
No coding experience is required. Developers can access advanced configuration options through the settings interface or API.
💡 Use Cases
ImgR is suitable for a wide range of applications:
- Business Intelligence: performance monitoring, KPI dashboards
- Project Management: workflow visualization, Gantt charts
- Academic Research: data analysis, scientific visualization
- Marketing & Insights: customer segmentation, campaign tracking
- Product Analytics: feature adoption, usage trends
- Education: classroom demonstrations, interactive learning
- System Architecture: network diagrams, infrastructure mapping
- Strategic Planning: organizational charts, roadmap visualization
🛠️ Advanced Configuration
- Data Sources: Connect via CSV, JSON, SQL databases, or REST APIs
- Custom Scripts: Extend functionality with JavaScript hooks
- Automation: Schedule auto-refresh for live dashboards
- Collaboration: Share interactive visualizations with teams via links or embeds
- Accessibility: WCAG-compliant themes and keyboard navigation
🗺️ Roadmap
Future releases of ImgR aim to include:
- 🤖 AI-assisted visualization suggestions
- 👥 Real-time multi-user collaboration
- 📊 Additional chart and layout types (radar charts, Sankey diagrams, 3D plots)
- 🔌 Plugin support for third-party add-ons
- 📑 Automated report generation
- 🌐 Cloud sync and cross-device support
- 🧩 Integration with popular platforms (Excel, Google Sheets, Notion, Jira)
📚 Documentation
Full documentation is available in the Docs folder or on the official website (coming soon).
Topics include:
- Installation & setup
- Visualization gallery
- API reference
- Advanced customization
- Troubleshooting & FAQs
🤝 Contributing
We welcome contributions from the community!
To contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature-name)
- Commit changes (
git commit -m "Add feature")
- Push to branch (
git push origin feature-name)
- Open a Pull Request
Please review our Contribution Guidelines before submitting.
🧪 Testing
ImgR includes unit tests and integration tests to ensure reliability.
Run tests locally with:
npm run test
## Calculator
```java
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private TextView inputBox;
private double firstNumber = 0;
private String operator = "";
private boolean isNewOperation = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
inputBox = findViewById(R.id.inputBox);
int[] numberButtons = {R.id.zero, R.id.one, R.id.two, R.id.three, R.id.four, R.id.five,
R.id.six, R.id.seven, R.id.eight, R.id.nine, R.id.point};
View.OnClickListener numberClickListener = v -> {
Button b = (Button) v;
if (isNewOperation) {
inputBox.setText("");
isNewOperation = false;
}
inputBox.append(b.getText().toString());
};
for (int id : numberButtons) {
findViewById(id).setOnClickListener(numberClickListener);
}
int[] operatorButtons = {R.id.plus, R.id.subtract, R.id.multiply, R.id.divide};
View.OnClickListener operatorClickListener = v -> {
Button b = (Button) v;
firstNumber = Double.parseDouble(inputBox.getText().toString());
operator = b.getText().toString();
isNewOperation = true;
};
for (int id : operatorButtons) {
findViewById(id).setOnClickListener(operatorClickListener);
}
findViewById(R.id.equals).setOnClickListener(v -> {
double secondNumber = Double.parseDouble(inputBox.getText().toString());
double result = 0;
switch (operator) {
case "+":
result = firstNumber + secondNumber;
break;
case "-":
result = firstNumber - secondNumber;
break;
case "×":
result = firstNumber * secondNumber;
break;
case "÷":
result = secondNumber == 0 ? 0 : firstNumber / secondNumber;
break;
}
inputBox.setText(String.valueOf(result));
isNewOperation = true;
});
findViewById(R.id.text_clear).setOnClickListener(v -> {
inputBox.setText("0");
firstNumber = 0;
operator = "";
isNewOperation = true;
});
}
}
BMI Calculator (Java)
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
EditText etWeight = findViewById(R.id.etWeight);
EditText etHeight = findViewById(R.id.etHeight);
TextView result = findViewById(R.id.result);
Button btnCalculate = findViewById(R.id.btnCalculate);
btnCalculate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
float height = Float.parseFloat(etHeight.getText().toString()) * 0.01f;
float weight = Float.parseFloat(etWeight.getText().toString());
float bmi = weight / (height * height);
result.setText(String.valueOf(bmi));
}
});
}
}
Currency Conv
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Objects;
public class MainActivity extends AppCompatActivity {
ArrayList<String> currencyList = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
currencyList.add("USD");
currencyList.add("INR");
currencyList.add("JPY");
Spinner convertFrom = findViewById(R.id.convertFrom);
Spinner convertTo = findViewById(R.id.convertTo);
Button calculate = findViewById(R.id.calculate);
TextView result = findViewById(R.id.result);
EditText convertFromValue = findViewById(R.id.convertFromValue);
Button swap = findViewById(R.id.swap);
calculate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String fromCurrency = currencyList.get(convertFrom.getSelectedItemPosition());
String toCurrency = currencyList.get(convertTo.getSelectedItemPosition());
float inputValue = Float.parseFloat(convertFromValue.getText().toString());
double outputValue;
if (Objects.equals(fromCurrency, currencyList.get(0))
&& Objects.equals(toCurrency, currencyList.get(1))) {
outputValue = inputValue / 0.012;
result.setText(String.valueOf(outputValue));
} else if (Objects.equals(fromCurrency, currencyList.get(0))
&& Objects.equals(toCurrency, currencyList.get(2))) {
outputValue = inputValue / 0.0067;
result.setText(String.valueOf(outputValue));
} else if (Objects.equals(fromCurrency, currencyList.get(1))
&& Objects.equals(toCurrency, currencyList.get(0))) {
outputValue = inputValue * 0.012;
result.setText(String.valueOf(outputValue));
} else if (Objects.equals(fromCurrency, currencyList.get(1))
&& Objects.equals(toCurrency, currencyList.get(2))) {
outputValue = inputValue * 1.171;
result.setText(String.valueOf(outputValue));
} else if (Objects.equals(fromCurrency, currencyList.get(2))
&& Objects.equals(toCurrency, currencyList.get(0))) {
outputValue = inputValue * 0.0067;
result.setText(String.valueOf(outputValue));
} else if (Objects.equals(fromCurrency, currencyList.get(2))
&& Objects.equals(toCurrency, currencyList.get(1))) {
outputValue = inputValue / 0.58;
result.setText(String.valueOf(outputValue));
} else {
result.setText(String.valueOf(inputValue));
}
}
});
ArrayAdapter<String> currAdapter = new ArrayAdapter<>(getApplicationContext(),
android.R.layout.simple_list_item_1,
currencyList
);
convertFrom.setAdapter(currAdapter);
convertTo.setAdapter(currAdapter);
}
}
Explicit Intent
// MainActivity.java
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CalendarView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText studentName = findViewById(R.id.nameInput);
EditText emailAddress = findViewById(R.id.emailInput);
EditText phoneNumber = findViewById(R.id.phoneInput);
EditText rollNo = findViewById(R.id.rollNumberInput);
EditText course = findViewById(R.id.courseInput);
EditText department = findViewById(R.id.departmentInput);
EditText address = findViewById(R.id.addressInput);
ImageView sourceImg = findViewById(R.id.profileImage);
sourceImg.setImageResource(R.mipmap.panik);
Button submitBtn = findViewById(R.id.submitBtn);
submitBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent explicitIntent = new Intent(getApplicationContext(), InfoDisplay.class);
explicitIntent.putExtra("StudentName", studentName.getText().toString());
explicitIntent.putExtra("EmailAddress", emailAddress.getText().toString());
explicitIntent.putExtra("PhoneNumber",
Integer.parseInt(phoneNumber.getText().toString())
);
explicitIntent.putExtra("RollNo",
Integer.parseInt(rollNo.getText().toString())
);
explicitIntent.putExtra("Course", course.getText().toString());
explicitIntent.putExtra("Department", department.getText().toString());
explicitIntent.putExtra("Address", address.getText().toString());
explicitIntent.putExtra("profileImage", R.mipmap.panik);
startActivity(explicitIntent);
};
});
}
}
// InfoDisplay.java
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
public class InfoDisplay extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_info_display);
TextView studentName = findViewById(R.id.nameDisplay);
TextView emailAddress = findViewById(R.id.emailDisplay);
TextView phoneNumber = findViewById(R.id.phoneDisplay);
TextView rollNo = findViewById(R.id.rollNumberDisplay);
TextView course = findViewById(R.id.courseDisplay);
TextView department = findViewById(R.id.departmentDisplay);
TextView address = findViewById(R.id.addressDisplay);
ImageView profileImage = findViewById(R.id.profileImg);
studentName.setText(getIntent().getStringExtra("StudentName"));
emailAddress.setText(getIntent().getStringExtra("EmailAddress"));
phoneNumber.setText(
String.valueOf(getIntent().getIntExtra("PhoneNumber", 99999999))
);
rollNo.setText(
String.valueOf(getIntent().getIntExtra("RollNo", 0))
);
course.setText(getIntent().getStringExtra("Course"));
department.setText(getIntent().getStringExtra("Department"));
address.setText(getIntent().getStringExtra("Address"));
profileImage.setImageResource(getIntent().getIntExtra("profileImage", R.mipmap.panik));
}
}
Implicit Intent
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button browseBtn, dialBtn, callBtn, smsBtn, shareBtn, emailBtn, appBtn;
browseBtn = findViewById(R.id.browseBtn);
dialBtn = findViewById(R.id.dialBtn);
callBtn = findViewById(R.id.callBtn);
smsBtn = findViewById(R.id.smsBtn);
shareBtn = findViewById(R.id.shareBtn);
emailBtn = findViewById(R.id.emailBtn);
appBtn = findViewById(R.id.appBtn);
browseBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent browseIntent = new Intent();
browseIntent.setAction(Intent.ACTION_VIEW);
String url = "https://siesascs.edu.in/";
browseIntent.setData(Uri.parse(url));
startActivity(browseIntent);
}
});
dialBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent dialIntent = new Intent();
dialIntent.setAction(Intent.ACTION_DIAL);
dialIntent.setData(Uri.parse("tel: +91 99387 46374"));
startActivity(dialIntent);
}
});
callBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent callIntent = new Intent();
callIntent.setAction(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel: +91 99387 46374"));
startActivity(callIntent);
}
});
smsBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent smsIntent = new Intent();
smsIntent.setAction(Intent.ACTION_SENDTO);
smsIntent.setData(Uri.parse("smsto:" + Uri.encode("+91 99387 46374")));
smsIntent.putExtra("sms_body", "There is a sun");
startActivity(smsIntent);
}
});
shareBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Ram loves Amit");
shareIntent.setType("text/plain");
startActivity(shareIntent);
}
});
emailBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent emailIntent = new Intent();
emailIntent.setAction(Intent.ACTION_SENDTO);
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {
"ramshukla@gmail.com",
"amitprajapati@gmail.com"
});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Love Letter");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Ram loves Amit very deeply");
emailIntent.setType("message/rfc822");
startActivity(emailIntent);
}
});
appBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent appIntent = new Intent();
appIntent.setAction(Intent.ACTION_SEND);
appIntent.putExtra(Intent.EXTRA_TEXT, "Ram loves Amit");
appIntent.setType("text/plain");
startActivity(appIntent);
}
});
}
}
Shared Preferences
// MainActivity.java
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
SharedPreferences sharedPreferences = getSharedPreferences("LoginPrefs", MODE_PRIVATE);
boolean isLoggedIn = sharedPreferences.getBoolean("isLoggedIn", false);
if (isLoggedIn) {
startActivity(new Intent(MainActivity.this, HomeActivity.class));
} else {
startActivity(new Intent(MainActivity.this, LoginActivity.class));
}
finish();
}
}
// LoginActivity.java
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class LoginActivity extends AppCompatActivity {
EditText etUsername, etPassword;
CheckBox cbRememberMe;
Button btnLogin;
SharedPreferences sharedPreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_login);
etUsername = findViewById(R.id.etUsername);
etPassword = findViewById(R.id.etPassword);
cbRememberMe = findViewById(R.id.cbRememberMe);
btnLogin = findViewById(R.id.btnLogin);
sharedPreferences = getSharedPreferences("LoginPrefs", MODE_PRIVATE);
String savedUsername = sharedPreferences.getString("username", "");
String savedPassword = sharedPreferences.getString("password", "");
boolean isLoggedIn = sharedPreferences.getBoolean("isLoggedIn", false);
if (!savedUsername.isEmpty()) {
etUsername.setText(savedUsername);
}
if (!savedPassword.isEmpty()) {
etPassword.setText(savedPassword);
}
cbRememberMe.setChecked(isLoggedIn);
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String username = etUsername.getText().toString();
String password = etPassword.getText().toString();
if (username.equals(getString(R.string.username))
&& password.equals(getString(R.string.password))) {
if (cbRememberMe.isChecked()) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("isLoggedIn", true);
editor.putString("username", username);
editor.apply();
}
startActivity(new Intent(LoginActivity.this, HomeActivity.class));
finish();
} else {
Toast.makeText(LoginActivity.this, "Invalid Credentials", Toast.LENGTH_SHORT).show();
}
}
});
}
}
// HomeActivity.java
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class HomeActivity extends AppCompatActivity {
TextView tvWelcome;
Button btnLogout;
SharedPreferences sharedPreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_home);
tvWelcome = findViewById(R.id.tvWelcome);
btnLogout = findViewById(R.id.btnLogout);
sharedPreferences = getSharedPreferences("LoginPrefs", MODE_PRIVATE);
String username = sharedPreferences.getString("username", "User");
tvWelcome.setText("Welcome, " + username);
btnLogout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.clear();
editor.apply();
startActivity(new Intent(HomeActivity.this, LoginActivity.class));
finish();
}
});
}
}
Alerts
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private EditText usernameInput, passwordInput;
private SharedPreferences sharedPreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
usernameInput = findViewById(R.id.usernameInput);
passwordInput = findViewById(R.id.passwordInput);
Button loginButton = findViewById(R.id.loginButton);
sharedPreferences = getSharedPreferences("auth_prefs", MODE_PRIVATE);
checkPreviousLogin();
loginButton.setOnClickListener(v -> showSaveCredentialsDialog());
}
private void showSaveCredentialsDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Save Credentials?");
builder.setMessage("Would you like to save your login credentials?");
builder.setPositiveButton("Yes", (dialog, id) -> {
saveAndProceed(true);
});
builder.setNegativeButton("No", (dialog, id) -> {
saveAndProceed(false);
});
AlertDialog dialog = builder.create();
dialog.show();
}
private void saveAndProceed(boolean saveCredentials) {
String username = usernameInput.getText().toString();
String password = passwordInput.getText().toString();
if (saveCredentials) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("username", username);
editor.putString("password", password);
editor.putBoolean("credentialsSaved", true);
editor.apply();
}
Intent intent = new Intent(MainActivity.this, WelcomeActivity.class);
intent.putExtra("username", username);
startActivity(intent);
finish();
}
private void checkPreviousLogin() {
if (sharedPreferences.getBoolean("credentialsSaved", false)) {
String savedUsername = sharedPreferences.getString("username", "");
String savedPassword = sharedPreferences.getString("password", "");
if (!savedUsername.isEmpty() && !savedPassword.isEmpty()) {
Intent intent = new Intent(MainActivity.this, WelcomeActivity.class);
intent.putExtra("username", savedUsername);
startActivity(intent);
finish();
}
}
}
}
// WelcomeActivity.java
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class WelcomeActivity extends AppCompatActivity {
private TextView welcomeText;
private SharedPreferences sharedPreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
welcomeText = findViewById(R.id.welcomeText);
Button logoutButton = findViewById(R.id.logoutButton);
sharedPreferences = getSharedPreferences("auth_prefs", MODE_PRIVATE);
String username = getIntent().getStringExtra("username");
welcomeText.setText("Welcome, " + username + "!");
logoutButton.setOnClickListener(v -> {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.clear();
editor.apply();
Intent intent = new Intent(WelcomeActivity.this, MainActivity.class);
startActivity(intent);
finish();
});
}
}
Notifications
import android.annotation.SuppressLint;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Build;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private static final String CHANNEL_ID = "notification_channel";
private static final int NOTIFICATION_ID = 101;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
createNotificationChannel();
Button notifyButton = findViewById(R.id.notifyButton);
notifyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sendNotification();
}
});
}
private void createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(
CHANNEL_ID,
"Notification Channel",
NotificationManager.IMPORTANCE_DEFAULT
);
NotificationManager manager = getSystemService(NotificationManager.class);
manager.createNotificationChannel(channel);
}
}
private void sendNotification() {
Intent intent = new Intent(this, TargetActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(
this,
0,
intent,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE
);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(android.R.drawable.ic_dialog_info)
.setContentTitle("Miinniii")
.setContentText("Click to see mini")
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(NOTIFICATION_ID, builder.build());
}
}
Int/Ext Storage
To check the location for saved text, Go to View -> Tool Window -> Device Manager
Location for Internal Storage -> `data -> data -> project package(eg., com.assignment) -> files -> messageFile.txt`
Location for External Storage -> `storage -> emulated -> 0 -> Android -> data -> project package -> files -> mydir -> sample.txt`
package com.assignment.android_practice;
import android.os.Bundle;
import android.os.Environment;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class MainActivity extends AppCompatActivity {
EditText inputText;
TextView outputText;
Button btnInternalSave, btnInternalLoad;
Button btnExternalSave, btnExternalLoad;
File externalFile;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main),
(v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
inputText = findViewById(R.id.editTextInput);
outputText = findViewById(R.id.textViewOutput);
btnInternalSave = findViewById(R.id.btnInternalSave);
btnInternalLoad = findViewById(R.id.btnInternalLoad);
btnExternalSave = findViewById(R.id.btnExternalSave);
btnExternalLoad = findViewById(R.id.btnExternalLoad);
// INTERNAL STORAGE
btnInternalSave.setOnClickListener(v -> {
String message = inputText.getText().toString();
try {
FileOutputStream fileOutputStream = openFileOutput("messageFile", MODE_PRIVATE);
OutputStreamWriter writer = new OutputStreamWriter(fileOutputStream);
writer.write(message);
writer.close();
Toast.makeText(this, "Saved to internal storage", Toast.LENGTH_SHORT).show();
inputText.setText("");
} catch (Exception e) {
e.printStackTrace();
}
});
btnInternalLoad.setOnClickListener(v -> {
StringBuilder message = new StringBuilder();
try {
FileInputStream fileInputStream = openFileInput("messageFile");
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
char[] buffer = new char[250];
int charRead;
while ((charRead = inputStreamReader.read(buffer)) > 0) {
message.append(buffer, 0, charRead);
}
inputStreamReader.close();
outputText.setText(message.toString());
Toast.makeText(this, "Loaded from internal storage", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
});
// EXTERNAL STORAGE
String externalState = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(externalState)) {
externalFile = new File(getExternalFilesDir("mydir"), "sample.txt");
}
btnExternalSave.setOnClickListener(v -> {
if (externalFile == null) {
Toast.makeText(this, "External storage not available", Toast.LENGTH_SHORT).show();
return;
}
try {
FileOutputStream fileOutputStream = new FileOutputStream(externalFile);
fileOutputStream.write(inputText.getText().toString().getBytes());
fileOutputStream.close();
Toast.makeText(this, "Saved to external storage", Toast.LENGTH_SHORT).show();
inputText.setText("");
} catch (Exception e) {
e.printStackTrace();
}
});
btnExternalLoad.setOnClickListener(v -> {
if (externalFile == null) {
Toast.makeText(this, "External storage not available", Toast.LENGTH_SHORT).show();
return;
}
StringBuilder message = new StringBuilder();
try {
FileInputStream fileInputStream = new FileInputStream(externalFile);
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
char[] buffer = new char[1024];
int charRead;
while ((charRead = inputStreamReader.read(buffer)) > 0) {
message.append(buffer, 0, charRead);
}
inputStreamReader.close();
outputText.setText(message.toString());
Toast.makeText(this, "Loaded from external storage", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
});
}
}
Animation
<!-- anim/alpha.xml -->
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="1"
android:toAlpha="0"
android:duration="500"
android:repeatCount="infinite"
/>
</set>
<!-- anim/rotate.xml -->
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:duration="500"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:startOffset="0"
android:toDegrees="360"
/>
</set>
<!-- anim/scale.xml -->
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:fromXScale="1"
android:toXScale="2"
android:fromYScale="1"
android:toYScale="2"
android:duration="1000"
android:startOffset="0"
android:repeatCount="infinite"
/>
</set>
<!-- anim/translate.xml -->
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/bounce_interpolator"
>
<translate android:fromXDelta="30"
android:toXDelta="300"
android:fromYDelta="0"
android:toYDelta="0"
android:duration="150"
android:repeatCount="infinite"
android:repeatMode="restart"
/>
</set>
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
private boolean isGray, isInvert = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView image = findViewById(R.id.imageView);
Button translate, rotate, scale, grey, invert;
translate = findViewById(R.id.translate);
rotate = findViewById(R.id.rotate);
scale = findViewById(R.id.scale);
grey = findViewById(R.id.grey);
invert = findViewById(R.id.invert);
translate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Animation translateAnim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.translate);
image.startAnimation(translateAnim);
}
});
rotate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Animation rotateAnim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotate);
image.startAnimation(rotateAnim);
}
});
scale.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Animation scaleAnim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.scale);
image.startAnimation(scaleAnim);
}
});
grey.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
grayImage();
}
private void grayImage() {
Bitmap originalBitmap = BitmapFactory.decodeResource(
getResources(),
R.drawable.img
);
Bitmap grayscaleBitmap =
Bitmap.createBitmap(
originalBitmap.getWidth(),
originalBitmap.getHeight(),
originalBitmap.getConfig()
);
if (isGray) {
image.setImageBitmap(originalBitmap);
isGray = false;
} else {
for (int x = 0; x < originalBitmap.getWidth(); x++) {
for (int y = 0; y < originalBitmap.getHeight(); y++) {
int pixel = originalBitmap.getPixel(x, y);
int alpha = Color.alpha(pixel);
int gray = (Color.red(pixel) + Color.green(pixel) + Color.blue(pixel)) / 3;
grayscaleBitmap.setPixel(x, y, Color.argb(
alpha, gray, gray, gray
));
}
}
image.setImageBitmap(grayscaleBitmap);
isGray = true;
}
}
});
invert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
invertImage();
}
private void invertImage() {
Bitmap originalBitmap = BitmapFactory.decodeResource(
getResources(),
R.drawable.img
);
Bitmap grayscaleBitmap =
Bitmap.createBitmap(
originalBitmap.getWidth(),
originalBitmap.getHeight(),
originalBitmap.getConfig()
);
if (isInvert) {
image.setImageBitmap(originalBitmap);
isInvert = false;
} else {
for (int x = 0; x < originalBitmap.getWidth(); x++) {
for (int y = 0; y < originalBitmap.getHeight(); y++) {
int pixel = originalBitmap.getPixel(x, y);
int alpha = Color.alpha(pixel);
int red = 255 - Color.red(pixel);
int green = 255 - Color.green(pixel);
int blue = 255 - Color.blue(pixel);
grayscaleBitmap.setPixel(x, y, Color.argb(
alpha, red, green, blue
));
}
}
image.setImageBitmap(grayscaleBitmap);
isInvert = true;
}
}
});
}
}