-
Notifications
You must be signed in to change notification settings - Fork 0
updated style #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
iliass-dahman
wants to merge
2
commits into
main
Choose a base branch
from
mobile-app
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "java.configuration.updateBuildConfiguration": "interactive" | ||
| } |
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
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
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
166 changes: 166 additions & 0 deletions
166
MobileApp/app/src/main/java/com/qrcodecopier/qrscanner/RedirectionActivity.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| package com.qrcodecopier.qrscanner; | ||
|
|
||
| import androidx.appcompat.app.AppCompatActivity; | ||
|
|
||
| import android.annotation.SuppressLint; | ||
| import android.graphics.Color; | ||
| import android.os.AsyncTask; | ||
| import android.os.Bundle; | ||
| import android.os.Handler; | ||
| import android.os.Looper; | ||
| import android.util.Log; | ||
| import android.util.Pair; | ||
| import android.view.View; | ||
| import android.widget.Button; | ||
| import android.widget.EditText; | ||
| import android.widget.TextView; | ||
| import android.widget.Toast; | ||
|
|
||
| import com.qrcodecopier.qrscanner.utils.MyProperties; | ||
| import com.qrcodecopier.qrscanner.utils.Utils; | ||
|
|
||
| import java.io.ByteArrayOutputStream; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.io.OutputStream; | ||
| import java.net.HttpURLConnection; | ||
| import java.net.URL; | ||
| import java.util.concurrent.Executor; | ||
| import java.util.concurrent.Executors; | ||
|
|
||
| public class RedirectionActivity extends AppCompatActivity { | ||
|
|
||
| Button submitBtn; | ||
| EditText urlInput; | ||
|
|
||
| TextView alertText, resultText; | ||
|
|
||
| String token; | ||
|
|
||
| @Override | ||
| protected void onCreate(Bundle savedInstanceState) { | ||
| super.onCreate(savedInstanceState); | ||
| setContentView(R.layout.activity_redirection); | ||
|
|
||
| submitBtn = findViewById(R.id.submit); | ||
| urlInput = findViewById(R.id.urlInput); | ||
| alertText = findViewById(R.id.alertmsg); | ||
| resultText = findViewById(R.id.resultmsg); | ||
|
|
||
|
|
||
| if (getIntent().hasExtra("token")){ | ||
| processToken(getIntent().getStringExtra("token")); | ||
| }else { | ||
| processToken(null); | ||
| } | ||
|
|
||
| submitBtn.setOnClickListener(new View.OnClickListener() { | ||
| @Override | ||
| public void onClick(View view) { | ||
| String input = urlInput.getText().toString(); | ||
| if (input.length() != 0){ //needs improvement | ||
| if (verifyUrl(input)) | ||
| sendUrl(input); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| private void showResult(String msg,boolean positive){ | ||
| resultText.setText(msg); | ||
| if (positive){ | ||
| resultText.setTextColor(Color.BLACK); | ||
| resultText.setBackgroundColor(Color.parseColor("#89FC00")); | ||
| }else { | ||
| resultText.setTextColor(Color.WHITE); | ||
| resultText.setBackgroundColor(Color.parseColor("#DC0073")); | ||
| } | ||
| } | ||
| private boolean verifyUrl(String url){ | ||
| String regex = "^((http|https)://)?(www\\.)?[a-zA-Z0-9]+(\\.[a-zA-Z]{2,})+(/.*)?$"; | ||
| return url.matches(regex); | ||
| } | ||
| private void processToken(String token){ | ||
| String positiveMsg=getResources().getString(R.string.positive_msg); | ||
| String negativeMsg=getResources().getString(R.string.negative_msg); | ||
| if (token == null || notAsExpected(token)){ | ||
| this.token = null; | ||
| alertText.setText(negativeMsg); | ||
| alertText.setTextColor(Color.WHITE); | ||
| alertText.setBackgroundColor(Color.parseColor("#DC0073")); | ||
| }else{ | ||
| this.token = token; | ||
| alertText.setText(positiveMsg); | ||
| alertText.setTextColor(Color.BLACK); | ||
| alertText.setBackgroundColor(Color.parseColor("#89FC00")); | ||
| } | ||
| } | ||
|
|
||
| private boolean notAsExpected(String token){ | ||
| return token.contains(" ;)({}:"); | ||
| } | ||
| private void sendUrl(String url){ | ||
| if (token != null){ | ||
| MyTask task = new MyTask(); | ||
| task.execute(url); | ||
| }else { | ||
| String error= "Error: No token included"; | ||
| showResult(error,false); | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
| @SuppressLint("StaticFieldLeak") | ||
| private class MyTask extends AsyncTask<String, Void, Pair<String,Boolean>> { | ||
|
|
||
| MyProperties properties = MyProperties.getInstance(); | ||
| protected Pair<String,Boolean> doInBackground(String... params) { | ||
| String responseBody; | ||
| boolean success = true; | ||
| try { | ||
| URL endpoint = new URL(properties.getServerURl()); | ||
| HttpURLConnection connection = (HttpURLConnection) endpoint.openConnection(); | ||
| connection.setRequestMethod("POST"); | ||
| connection.setRequestProperty("Content-Type", "application/json"); | ||
| connection.setDoOutput(true); | ||
|
|
||
| String requestBody = Utils.buildRequestBody(token,params[0]); | ||
|
|
||
| OutputStream outputStream = connection.getOutputStream(); | ||
| outputStream.write(requestBody.getBytes()); | ||
| outputStream.flush(); | ||
| outputStream.close(); | ||
|
|
||
| int responseCode = connection.getResponseCode(); | ||
| if (responseCode == HttpURLConnection.HTTP_OK) { | ||
| InputStream inputStream = connection.getInputStream(); | ||
| responseBody="Done. "; | ||
| responseBody += readStream(inputStream); | ||
| inputStream.close(); | ||
| } else { | ||
| responseBody = "HTTP Error: " + responseCode; | ||
| success = false; | ||
| } | ||
| connection.disconnect(); | ||
| } catch (Exception e) { | ||
| responseBody = e.toString(); | ||
| success = false; | ||
|
|
||
| } | ||
| return new Pair<>(responseBody,success); | ||
| } | ||
| private String readStream(InputStream inputStream) throws IOException { | ||
| ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | ||
| byte[] buffer = new byte[1024]; | ||
| int bytesRead = 0; | ||
| while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| outputStream.write(buffer, 0, bytesRead); | ||
| } | ||
| return outputStream.toString(); | ||
| } | ||
| protected void onPostExecute(Pair<String, Boolean> result) { | ||
| showResult(result.first,result.second); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.